This article mainly describes the "target=" based on codeigniterhttp://www.php.cn/css/css-rwd-frameworks.html "_blank" > Framework implementation of the Student information system site dynamic release function, detailed analysis of the dynamic site-related database SQL statements, MVC each module function and implementation skills, the need for friends can refer to the next
This paper describes the dynamic publishing function of student information system based on CodeIgniter framework. Share to everyone for your reference, as follows:
Since it is a dynamic site, there must be a database table exists, in this no nonsense, let's look at the database table:
CREATE TABLE IF not EXISTS ' student ' ( //primary key ID ' ID ' int (one) not NULL auto_increment, //Student name ' S_name ' varchar (+) NOT NULL, //student Parent's name ' p_name ' varchar (+) NOT NULL, //Student's home address ' address ' varchar NULL, //Cities ' city ' varchar (+) NOT NULL, //Country ' state ' varchar (+) NOT NULL,/ / ZIP/Postal Code ' Zip ' varchar (+) NOT NULL,// telephone ' phone ' varchar (not NULL), //Mail ' email ' varchar () not NULL, //primary key set PRIMARY key (' id ')) engine=innodb default Charset=utf8 auto_increment=1;
* Note: Here I have two places to explain:
1. "If not EXISTS": If the data is in the creation of the table, preceded by the "If not EXISTS", it means that even if the table already exists, it will execute successfully;
2. "Engine=innodb": This is the database engine settings, commonly used MySQL database engine isam,myisam,heap and so on;
After creating the data table, let's look at the database connection. Open the. \application\config\database.php file, set the database variable parameter inside, set the base URL within the. \application\config\config.php file, The basic URL for me is: localhost/codeigniter/
Let's look at the design of MVC thought architecture
First open the. application\controllers\ file directory and create a student.php controller inside it:
student.php
Here we first pass student this controller to test, print out the HelloWorld, remember the access path is: Localhost/codeigniter/index.php/student/index
Class Student extends ci_controller{ //student Controller construct public function construct () { Parent:: Construct (); } Index test function Public function index () { echo "HelloWorld"; }}
It Output:helloworld
Let's change it and see the following code:
Class Student extends ci_controller{ //student Controller public function construct () { parent::construct (); } Define a array,name is Arraydata, it has three parameters protected $arraydata =array ( ' title ' = ' Classroom ') : Home page ', ' headline ' + ' Welcome to the classroom Mangement System ', ' include ' = ' student_index ' ) ; Index function public function index () { $this->load->view (' template ', $this->arraydata);} }
This code requires a view, template.php
template.php:
<! DOCTYPE HTML public '-//w3c//dtd HTML 4.01 strict//en ' HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD ' >
which
This−>load−>view (include);
Contains a different view file studen_index.php file
student_index.php:
<p>congratulations. Your Initial setup is complete!</p>
Combined output:
Welcome to the Classroom Mangement systemcongratulations. Your Initial setup is complete!
Curd of data
C Controller
Let's take a look at the data increase process and add an Add () method to the student controller
Class Student extends ci_controller{//student Controller public Function construct () {parent::construct (); }//new Add function Public Function Add () {$this->load->helper (' form '); Display information for the view $data [' title ']= ' Classroom:add Page '; $data [' Headline ']= ' ADD data '; $data [' Include ']= ' student_add '; Upload View $this->load->view (' template ', $data); }//create function Public function Create () {$this->load->helper (' url '); $this->load->model (' mstudent ', ', TRUE); $this->mstudent->adddata ($_post); Redirect (' Student/add ', ' Reflesh '); }//update function Public Function Update () {//upload CodeIgniter library $this->load->library (' tab Le '); $this->load->model (' mstudent ', ', TRUE); $student _query= $this->mstudent->updatedata (); $update _table= $this->table->generate ($student _query); Display information for thE view $data [' title ']= ' Classroom:update Page '; $data [' Headline ']= ' Update Page '; $data [' Include ']= ' update_student '; $data [' updatetable ']= $update _table; $this->load->view (' template ', $data); }//index function Public Function index () {$data [' title ']= ' Classroom:home page '; $data [' Headline ']= ' Welcome to Classroom mangement System '; $data [' Include ']= ' student_index '; $this->load->view (' template ', $this->arraydata); }}
V View
Template. php
student_add.php
<?php Echo form_open (' student/create '); $field _name=array (' s_name ', ' p_name ', ' address ', ' City ', ' state ', ' zip ', ' phone ', ' email '); foreach ($field _name as $value) { echo <p> $value. ":" Echo form_input (Array (' name ' = = $value)); echo "</p>" } form_submit (', ' Add '); Form_close ();? >
update_student.php
<?php echo $updatetable;? >
M model
class mstudent extends ci_model{public function AddData ($data) {$this->DB-&G T;insert (' student ', $data); } public Function UpdateData () {$this->db->get (' student '); }}