基于Codeigniter框架实现的student信息系统站点动态发布功能详解

2019-05-01 21:23:03刘景俊

本文实例讲述了基于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

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

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

首先打开.applicationcontrollers文件目录,在里面创建一个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>
  <h1><?php echo $headline; ?></h1>
  <?php $this->load->view($include)?>
</body>
</html>

								 
			 
相关文章 大家在看