Home Backend Development PHP Tutorial Detailed explanation of the case of dynamic publishing function code for student information system site based on Codeigniter framework

Detailed explanation of the case of dynamic publishing function code for student information system site based on Codeigniter framework

Mar 24, 2017 am 09:32 AM
codeigniter student Dynamic publishing

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;
Copy after login

*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";
    }
}
Copy after login

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);
    }
}
Copy after login

This code requires a view, template.php

template.php:

<!DOCTYPE html PUBLIC &#39;-//W3C//DTD HTML 4.01 Strict//EN&#39; &#39;http://www.w3.org/TR/html4/strict.dtd&#39;>
<html>
<head>
<meta http-equiv=&#39;Content-Type&#39; content=&#39;text/html; charset=utf-8&#39;>
<title><?php echo $title; ?></title>
</head>
<body>
  <h1><?php echo $headline; ?></h1>
  <?php $this->load->view($include)?>
</body>
</html>
Copy after login

Among them:

this−>load−>view(include);
Copy after login

contains another view file student_index.php file

student_index.php:

<p>Congratulations. Your initial setup is complete!</p>
Copy after login

Joint output:

welcome to the classroom Mangement System
Congratulations. Your initial setup is complete!
Copy after login

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(&#39;form&#39;);
      //display information for the view
      $data[&#39;title&#39;]=&#39;Classroom:Add Page&#39;;
      $data[&#39;headline&#39;]=&#39;Add data&#39;;
      $data[&#39;include&#39;]=&#39;student_add&#39;;
      //upload view
      $this->load->view(&#39;template&#39;,$data);
    }
    //create function
    public function create(){
      $this->load->helper(&#39;url&#39;);
      $this->load->model(&#39;MStudent&#39;,&#39;&#39;,TRUE);
      $this->MStudent->addData($_POST);
      redirect(&#39;student/add&#39;,&#39;reflesh&#39;);
    }
    //update function
    public function update(){
      //upload codeigniter library
      $this->load->library(&#39;table&#39;);
      $this->load->model(&#39;MStudent&#39;,&#39;&#39;,TRUE);
      $student_query=$this->MStudent->updateData();
      $update_table=$this->table->generate($student_query);
      //display information for the view
      $data[&#39;title&#39;]=&#39;Classroom:Update Page&#39;;
      $data[&#39;headline&#39;]=&#39;Update Page&#39;;
      $data[&#39;include&#39;]=&#39;update_student&#39;;
      $data[&#39;updatetable&#39;]=$update_table;
      $this->load->view(&#39;template&#39;,$data);
    }
    //index function
    public function index(){
      $data[&#39;title&#39;]=&#39;Classroom:Home page&#39;;
      $data[&#39;headline&#39;]=&#39;welcome to classroom Mangement System&#39;;
      $data[&#39;include&#39;]=&#39;student_index&#39;;
      $this->load->view(&#39;template&#39;,$this->arraydata);
    }
}
Copy after login

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>
Copy after login

student_add.php

<?php
  echo form_open(&#39;student/create&#39;);
  $field_name=array(&#39;s_name&#39;,&#39;p_name&#39;,&#39;address&#39;,&#39;city&#39;,&#39;state&#39;,&#39;zip&#39;,&#39;phone&#39;,&#39;email&#39;);
  foreach($field_name as $value){
    echo "<p>".$value.":"
    echo form_input(array(&#39;name&#39;=>$value));
    echo "</p>"
  }
  form_submit(&#39;&#39;,&#39;Add&#39;);
  form_close();
?>
Copy after login

update_student.php

<?php
  echo $updatetable;
?>
Copy after login

M Model

class MStudent extends CI_Model{
  public function addData($data){
    $this->db->insert(&#39;student&#39;,$data);
  }
  public function updateData(){
    $this->db->get(&#39;student&#39;);
  }
}
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement custom middleware in CodeIgniter How to implement custom middleware in CodeIgniter Jul 29, 2023 am 10:53 AM

How to implement custom middleware in CodeIgniter Introduction: In modern web development, middleware plays a vital role in applications. They can be used to perform some shared processing logic before or after the request reaches the controller. CodeIgniter, as a popular PHP framework, also supports the use of middleware. This article will introduce how to implement custom middleware in CodeIgniter and provide a simple code example. Middleware overview: Middleware is a kind of request

CodeIgniter middleware: Accelerate application responsiveness and page rendering CodeIgniter middleware: Accelerate application responsiveness and page rendering Jul 28, 2023 pm 06:51 PM

CodeIgniter Middleware: Accelerating Application Responsiveness and Page Rendering Overview: As web applications continue to grow in complexity and interactivity, developers need to use more efficient and scalable solutions to improve application performance and responsiveness. . CodeIgniter (CI) is a lightweight PHP-based framework that provides many useful features, one of which is middleware. Middleware is a series of tasks that are performed before or after the request reaches the controller. This article will introduce how to use

How to use the database query builder (Query Builder) in the CodeIgniter framework How to use the database query builder (Query Builder) in the CodeIgniter framework Jul 28, 2023 pm 11:13 PM

Introduction to the method of using the database query builder (QueryBuilder) in the CodeIgniter framework: CodeIgniter is a lightweight PHP framework that provides many powerful tools and libraries to facilitate developers in web application development. One of the most impressive features is the database query builder (QueryBuilder), which provides a concise and powerful way to build and execute database query statements. This article will introduce how to use Co

PHP development: Using CodeIgniter to implement MVC pattern and RESTful API PHP development: Using CodeIgniter to implement MVC pattern and RESTful API Jun 16, 2023 am 08:09 AM

As web applications continue to evolve, it is important to develop applications more quickly and efficiently. And, as RESTful API is widely used in web applications, it is necessary for developers to understand how to create and implement RESTful API. In this article, we will discuss how to implement MVC pattern and RESTful API using CodeIgniter framework. Introduction to MVC pattern MVC (Model-Vie

Deal | Affordable HP Victus gaming laptop with RTX 3050-beating RX 6550M gets 40% discount in Best Buy sale Deal | Affordable HP Victus gaming laptop with RTX 3050-beating RX 6550M gets 40% discount in Best Buy sale Aug 09, 2024 pm 09:51 PM

The HP Victus 15 is 1 15.6-inch entry-level gaming laptop that ordinarily wouldn't be worth much consideration, however a new Best Buy deal offers 40% off the entry-level gaming laptop, bringing the price down from $799.99 to a very budget-friendly $

How to use CodeIgniter5 framework in php? How to use CodeIgniter5 framework in php? Jun 01, 2023 am 11:21 AM

CodeIgniter is a lightweight PHP framework that uses MVC architecture to support rapid development and simplify common tasks. CodeIgniter5 is the latest version of the framework and offers many new features and improvements. This article will introduce how to use the CodeIgniter5 framework to build a simple web application. Step 1: Install CodeIgniter5 Downloading and installing CodeIgniter5 is very simple, just follow these steps: Download the latest version

CodeIgniter middleware: Provides secure file upload and download functions CodeIgniter middleware: Provides secure file upload and download functions Aug 01, 2023 pm 03:01 PM

CodeIgniter middleware: Provides secure file upload and download functions Introduction: In the process of web application development, file upload and download are very common functions. However, for security reasons, handling file uploads and downloads often requires additional security measures. CodeIgniter is a popular PHP framework that provides a wealth of tools and libraries to support developers in building secure and reliable web applications. This article will introduce how to use CodeIgniter middleware to implement secure files

How to use the PHP framework CodeIgniter to quickly build a backend management system How to use the PHP framework CodeIgniter to quickly build a backend management system Jun 27, 2023 am 09:46 AM

In today's Internet era, a website that is loved by users must have a simple and clear front-end interface and a powerful back-end management system, and the PHP framework CodeIgniter is an excellent framework that allows developers to quickly build a back-end management system. CodeIgniter has the characteristics of lightweight, high efficiency, and easy expansion. This article will be aimed at beginners and explain in detail how to quickly build a backend management system through this framework. 1. Installation and configuration Installation of PHPCodeIgniter is a PHP-based

See all articles