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

本文实例讲述了基于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> <h1><?php echo $headline; ?></h1> <?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> <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 模型

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

更多关于CodeIgniter相关内容感兴趣的读者可查看本站专题:《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《php优秀开发框架总结》、《ThinkPHP入门教程》、《ThinkPHP常用方法总结》、《Zend FrameWork框架入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于CodeIgniter框架的PHP程序设计有所帮助。

时间: 2024-07-29 17:46:24

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

YII Framework框架教程之使用YIIC快速创建YII应用详解_php实例

本文实例讲述了YII Framework框架使用YIIC快速创建YII应用的方法.分享给大家供大家参考,具体如下: yii提供了强大的命令行工具来快速的创建相关组件和应用.</span>  cd进入yii/framework框架的根目录. 执行 # php yiic Yii command runner (based on Yii v1.1.8) Usage: yiic <command-name> [parameters...] The following commands ar

基于在生产环境中使用php性能测试工具xhprof的详解_php实例

xhprof 是facebook开源出来的一个php性能测试工具,也可以称之为profile工具,这个词不知道怎么翻译才比较达意.跟之前一直使用的xdebug相比,有很多类似之处.以前对xdebug有一些记录还可以供参考,但是它的缺点是对性能影响太大,即便是开启了profiler_enable_trigger参数,用在生产环境中也是惨不忍睹,cpu立刻就飙到high.而xhprof就显得很轻量,是否记录profile可以由程序控制,因此,用在生产环境中也就成为一种可能.在它的文档上可以看到这样一

【框架】[Spring]纯Java方式实现AOP拦截-详解ThrowsAdvice异常通知

转载请注明出处:http://blog.csdn.net/qq_26525215 本文源自[大学之旅_谙忆的博客] 这篇博客讲了AOP代理-通知的3种方式: 1.MethodBeforeAdvice-前置通知 2.AfterReturningAdvice-正常返回后通知 3.MethodInterceptor-环绕通知 [框架][Spring]纯Java的方式实现AOP切面(拦截)技术 现在本篇博客再详细讲解一下ThrowsAdvice-异常通知. 顾明思议,就是被代理的原型对象出异常了,就会运

Android基于BaseExpandableListAdapter实现的二级列表仿通话记录功能详解

本文实例讲述了Android基于BaseExpandableListAdapter实现的二级列表仿通话记录功能.分享给大家供大家参考,具体如下: android SDK中带有这样类似的例子,但是那个还是静态数据,没有实际应用价值,参考意义不大. 网上找了很多,还是那样的情况,几乎是同一篇文章,大家转来转去.况且,那篇例子也是静态的数据. 还是自己试试,自己写一个吧.程序读取手机系统的通话记录,按联系人分组,显示到列表. 开发工具:eclipse 运行环境:htc G9 android2.3.3

基于JavaScript实现继承机制之原型链(prototype chaining)的详解_javascript技巧

如果用原型方式重定义前面例子中的类,它们将变为下列形式: 复制代码 代码如下: function ClassA() {} ClassA.prototype.color = "blue";ClassA.prototype.sayColor = function () {    alert(this.color);}; function ClassB() {} ClassB.prototype = new ClassA(); 原型方式的神奇之处在于最后一行代码.这里,把 ClassB 的

python基于mysql实现的简单队列以及跨进程锁实例详解_python

通常在我们进行多进程应用开发的过程中,不可避免的会遇到多个进程访问同一个资源(临界资源)的状况,这时候必须通过加一个全局性的锁,来实现资源的同步访问(即:同一时间里只能有一个进程访问资源). 举个例子如下: 假设我们用mysql来实现一个任务队列,实现的过程如下: 1. 在Mysql中创建Job表,用于储存队列任务,如下: create table jobs( id auto_increment not null primary key, message text not null, job_s

基于获取JAVA路径,包括CLASSPATH外的路径的方法详解_java

归纳一些网上取JAVA路径的方法: 注明:如果从ANT启动程序,this.getClass().getResource("")取出来的比较怪,直接用JAVA命令行调试就可成功.得到classpath和当前类的绝对路径的一些方法获得CLASSPATH之外路径的方法:URL base = this.getClass().getResource(""): //先获得本类的所在位置,如/home/popeye/testjava/build/classes/net/ Stri

基于Android设计模式之--SDK源码之策略模式的详解_Android

策略模式其实特别简单(听到这句话,大家是不是心里一下子放松了?).比如排序,官方告诉大家我这里有一个排序的接口ISort的sort()方法,然后民间各尽其能,实现这个排序的方法:冒泡,快速,堆等等.这些方法就是"不同的策略".然后,某个模块下,需要一个排序方法,但是暂时不能指定具体的sort方法(出于扩展的考虑),就需要使用ISort接口了.最后,具体什么场景下,传入什么具体的sort方法,实现灵活的排序.这就是策略模式!下面,我们分析Android中的动画是如何使用策略模式的. 1.

基于JAVA中Jersey处理Http协议中的Multipart的详解_java

     那么Http协议中的Multipart是个什么东东?下面是摘抄http协议1.1的一段话:在multipart entity(多部分实体)的例子中,一个或多个不同的数据集合并在一个单一的body(体)中,一个"multipart"(多部分)类型 field的(域)必须出现在实体的header(头域).body(体)必须包括一个或多个body part(体部分),每一个位于boundary(边界)定界符线之前,最后一个则跟着一个结束边界定界符线.在它的边界定界符线后,每一个体部