使用Codeigniter框架怎么实现一个student信息系统站点动态发布功能

发布时间:2021-02-05 16:20:39 作者:Leah
来源:亿速云 阅读:124

这篇文章给大家介绍使用Codeigniter框架怎么实现一个student信息系统站点动态发布功能,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

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;

*注:在此我有两个地方需要解释一下:

1."IF NOT EXISTS":如果数据在创建表的时候,在前面加上了"IF NOT EXISTS",那就表明即使此表已经存在,也会执行成功;

2."ENGINE=INNODB":这个是数据库的引擎设置,常用mysql数据库引擎有ISAM,MYISAM,HEAP等;

具体参考资料:http://baike.baidu.com/view/68455.htm

在创建完数据表之后,我们再来看一下数据库的连接。打开.\application\config\database.php文件,在内设置数据库变量参数,在.\application\config\config.php文件内设置基本的URL,对于我的基本url是:http://localhost/codeigniter/

下面我们来看看mvc思想架构的设计

首先打开.application\controllers\文件目录,在里面创建一个student.php控制器:

student.php

在此我们先来通过student这个控制器来测试一下,打印出helloworld,记住访问路径是:http://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

下面我们来换一下,看看下面这段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);
    }
}

这段代码需要一个视图,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>
  <h2><?php echo $headline; ?></h2>
  <?php $this->load->view($include)?>
</body>
</html>

其中:

this−>load−>view(include);

包含的是另外一个视图文件studen_index.php文件

student_index.php:

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

联合输出:

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

数据的CURD

C 控制器

先来看看数据的增加过程,在student控制器中增加一个add()方法

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 视图

template .php

<html>
  <head>
    <title><?php echo $title;?></title>
  </head>
  <body>
    <h2><?php echo $headline ?></h2>
    <?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 模型

class MStudent extends CI_Model{
  public function addData($data){
    $this->db->insert('student',$data);
  }
  public function updateData(){
    $this->db->get('student');
  }
}

关于使用Codeigniter框架怎么实现一个student信息系统站点动态发布功能就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

推荐阅读:
  1. 怎么在CodeIgniter框架中使用redis
  2. CodeIgniter框架如何实现购物车功能

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

codeigniter student

上一篇:如何在thinkPHP3.2项目中接入微信

下一篇:如何在php中使用自定义函数记录log日志

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》