This article mainly introduces the student implemented based on the Codeigniterframework The dynamic publishing function of the information system site provides a detailed analysis of the database sql statements, MVC functions and implementation techniques of each module related to the dynamic site. Friends in need can refer to the following
This article describes an example based on Codeigniter The dynamic publishing function of the student information system site implemented by the framework is shared with everyone for your reference. The details are as follows:
Since it is a dynamic site, there must be a database table. Without further ado, let’s take a look at the database. Table:
CREATE TABLE IF NOT EXISTS `student`( //主键id `id` int(11) NOT NULL AUTO_INCREMENT, //学生姓名 `s_name` varchar(64) NOT NULL, //学生家长的姓名 `p_name` varchar(64) NOT NULL, //学生的家庭住址 `address` varchar(100) NOT NULL, //所在城市 `city` varchar(30) NOT NULL, //所在国家 `state` varchar(30) NOT NULL, //所在地区的邮政编码 `zip` varchar(20) NOT NULL, //电话 `phone` varchar(15) NOT NULL, //邮件 `email` varchar(20) NOT NULL, //主键设置 PRIMARY KEY(`id`) )ENGINE=INNODB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;
*Note: There are two places I need to explain here:
1. "IF NOT EXISTS": If the data is added in front when creating the table "IF NOT EXISTS" means that even if the table already exists, it will be executed successfully;
2. "ENGINE=INNODB": This is the engine setting of the database, commonly used mysql database Engines include ISAM, MYISAM, HEAP, etc.;
After creating the data table, let’s take a look at the database connection. Open the .\application\config\database.php file and set the database variable parameters in it. Set the basic URL in the .\application\config\config.php file. For me, the basic URL is: localhost/codeigniter/
Let’s take a look at the mvc ideaArchitecture Design
First open the .application\controllers\ file directory and create a student.phpcontroller:
student.php
In Let's first test it through the student controller and print out helloworld. Remember that 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 look at the following code:
class student extends CI_Controller{ //student controller public function construct(){ parent::construct(); } //define a array,name is arraydata, it have 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'> <html> <head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> <title><?php echo $title; ?></title> </head> <body> <h1><?php echo $headline; ?></h1> <?php $this->load->view($include)?> </body> </html>
Among them:
this−>load−>view(include);
contains another view file student_index.php file
student_index.php:
<p>Congratulations. Your initial setup is complete!</p>
Joint output:
welcome to the classroom Mangement System Congratulations. Your initial setup is complete!
CURD of data
C Controller
Let’s first look at the process of adding data, add an add() in the student controller Method
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('table'); $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
<html> <head> <title><?php echo $title;?></title> </head> <body> <h1><?php echo $headline ?></h1> <?php $this->load->view($include)?> </body> </html>
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->insert('student',$data); } public function updateData(){ $this->db->get('student'); } }
The above is the detailed content of Detailed explanation of the case of dynamic publishing function code for student information system site based on Codeigniter framework. For more information, please follow other related articles on the PHP Chinese website!