search
HomeBackend DevelopmentPHP TutorialDetailed explanation of the case of dynamic publishing function code for student information system site based on Codeigniter framework

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 &#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>

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(&#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);
    }
}

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(&#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();
?>

update_student.php

<?php
  echo $updatetable;
?>

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;);
  }
}

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
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
如何在CodeIgniter中实现自定义中间件如何在CodeIgniter中实现自定义中间件Jul 29, 2023 am 10:53 AM

如何在CodeIgniter中实现自定义中间件引言:在现代的Web开发中,中间件在应用程序中起着至关重要的作用。它们可以用来执行在请求到达控制器之前或之后执行一些共享的处理逻辑。CodeIgniter作为一个流行的PHP框架,也支持中间件的使用。本文将介绍如何在CodeIgniter中实现自定义中间件,并提供一个简单的代码示例。中间件概述:中间件是一种在请求

CodeIgniter中间件:加速应用程序的响应速度和页面渲染CodeIgniter中间件:加速应用程序的响应速度和页面渲染Jul 28, 2023 pm 06:51 PM

CodeIgniter中间件:加速应用程序的响应速度和页面渲染概述:随着网络应用程序的复杂性和交互性不断增长,开发人员需要使用更加高效和可扩展的解决方案来提高应用程序的性能和响应速度。CodeIgniter(CI)是一种基于PHP的轻量级框架,提供了许多有用的功能,其中之一就是中间件。中间件是在请求到达控制器之前或之后执行的一系列任务。这篇文章将介绍如何使用

在CodeIgniter框架中使用数据库查询构建器(Query Builder)的方法在CodeIgniter框架中使用数据库查询构建器(Query Builder)的方法Jul 28, 2023 pm 11:13 PM

在CodeIgniter框架中使用数据库查询构建器(QueryBuilder)的方法引言:CodeIgniter是一个轻量级的PHP框架,它提供了许多功能强大的工具和库,方便开发人员进行Web应用程序开发。其中一个令人印象深刻的功能是数据库查询构建器(QueryBuilder),它提供了一种简洁而强大的方法来构建和执行数据库查询语句。本文将介绍如何在Co

PHP开发:使用 CodeIgniter 实现 MVC 模式和 RESTful APIPHP开发:使用 CodeIgniter 实现 MVC 模式和 RESTful APIJun 16, 2023 am 08:09 AM

随着Web应用程序的不断发展,更加快速和高效地开发应用程序变得非常重要。并且,随着RESTfulAPI在Web应用程序中的广泛应用,对于开发人员来说,必须理解如何创建和实现RESTfulAPI。在本文中,我们将讨论如何使用CodeIgniter框架实现MVC模式和RESTfulAPI。MVC模式简介MVC(Model-Vie

php如何使用CodeIgniter5框架?php如何使用CodeIgniter5框架?Jun 01, 2023 am 11:21 AM

CodeIgniter是一个轻量级的PHP框架,采用MVC架构,支持快速开发和简化常见任务。CodeIgniter5是该框架的最新版本,提供了许多新的特性和改进。本文将介绍如何使用CodeIgniter5框架来构建一个简单的Web应用程序。步骤1:安装CodeIgniter5下载和安装CodeIgniter5非常简单,只需要遵循以下步骤:下载最新版本

如何使用PHP框架CodeIgniter快速搭建一个后台管理系统如何使用PHP框架CodeIgniter快速搭建一个后台管理系统Jun 27, 2023 am 09:46 AM

现今互联网时代,一款深受用户喜爱的网站必须具备简洁明了的前端界面和功能强大的后台管理系统,而PHP框架CodeIgniter则是一款能够让开发者快速搭建后台管理系统的优秀框架。CodeIgniter拥有轻量级、高效率、易扩展等特点,本文将针对初学者,详细说明如何通过该框架快速搭建一个后台管理系统。一、安装配置安装PHPCodeIgniter是一个基于PHP的

使用PHP框架CodeIgniter开发一个实时聊天应用,提供便捷的通讯服务使用PHP框架CodeIgniter开发一个实时聊天应用,提供便捷的通讯服务Jun 27, 2023 pm 02:49 PM

随着移动互联网的发展,即时通信变得越来越重要,越来越普及。对于很多企业而言,实时聊天更像是一种通信服务,提供便捷的沟通方式,可以快速有效地解决业务方面的问题。基于此,本文将介绍如何使用PHP框架CodeIgniter开发一个实时聊天应用。了解CodeIgniter框架CodeIgniter是一个轻量级的PHP框架,提供了一系列的简便的工具和库,帮助开发者快速

PHP实现框架:CodeIgniter入门教程PHP实现框架:CodeIgniter入门教程Jun 18, 2023 pm 10:43 PM

近年来,Web开发技术的进步和全球互联网应用的不断扩大,使得PHP技术应用面越来越广泛。作为一种快速开发的技术,其生态系统也在不断发展壮大。其中,CodeIgniter作为PHP开发领域中著名的框架之一,备受众多开发者的欢迎。本篇文章将介绍CodeIgniter框架的相关知识,以此为初学者提供一个入门的指引。一、什么是CodeIgniter框架?CodeIg

See all articles

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 agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),