最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于Codeigniter框架實(shí)現(xiàn)的student信息系統(tǒng)站點(diǎn)動(dòng)態(tài)發(fā)布功能詳解

 更新時(shí)間:2017年03月23日 11:58:00   作者:PHP__廊外詩(shī)鴿  
這篇文章主要介紹了基于Codeigniter框架實(shí)現(xiàn)的student信息系統(tǒng)站點(diǎn)動(dòng)態(tài)發(fā)布功能,詳細(xì)分析了動(dòng)態(tài)站點(diǎn)相關(guān)的數(shù)據(jù)庫(kù)sql語(yǔ)句、MVC各個(gè)模塊功能與實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了基于Codeigniter框架實(shí)現(xiàn)的student信息系統(tǒng)站點(diǎn)動(dòng)態(tài)發(fā)布功能。分享給大家供大家參考,具體如下:

既然是動(dòng)態(tài)站點(diǎn),肯定有數(shù)據(jù)庫(kù)表的存在,在此不廢話,下面我們來(lái)看一下數(shù)據(jù)庫(kù)表:

CREATE TABLE IF NOT EXISTS `student`(
    //主鍵id
    `id` int(11) NOT NULL AUTO_INCREMENT,
    //學(xué)生姓名
    `s_name` varchar(64) NOT NULL,
    //學(xué)生家長(zhǎng)的姓名
    `p_name` varchar(64) NOT NULL,
    //學(xué)生的家庭住址
    `address` varchar(100) NOT NULL,
    //所在城市
    `city`  varchar(30) NOT NULL,
    //所在國(guó)家
    `state` varchar(30) NOT NULL,
    //所在地區(qū)的郵政編碼
    `zip`  varchar(20) NOT NULL,
    //電話
    `phone` varchar(15) NOT NULL,
    //郵件
    `email` varchar(20) NOT NULL,
    //主鍵設(shè)置
    PRIMARY KEY(`id`)
)ENGINE=INNODB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;

*注:在此我有兩個(gè)地方需要解釋一下:

1."IF NOT EXISTS":如果數(shù)據(jù)在創(chuàng)建表的時(shí)候,在前面加上了"IF NOT EXISTS",那就表明即使此表已經(jīng)存在,也會(huì)執(zhí)行成功;

2."ENGINE=INNODB":這個(gè)是數(shù)據(jù)庫(kù)的引擎設(shè)置,常用mysql數(shù)據(jù)庫(kù)引擎有ISAM,MYISAM,HEAP等;

具體參考資料:http://baike.baidu.com/view/68455.htm

在創(chuàng)建完數(shù)據(jù)表之后,我們?cè)賮?lái)看一下數(shù)據(jù)庫(kù)的連接。打開(kāi).\application\config\database.php文件,在內(nèi)設(shè)置數(shù)據(jù)庫(kù)變量參數(shù),在.\application\config\config.php文件內(nèi)設(shè)置基本的URL,對(duì)于我的基本url是:http://localhost/codeigniter/

下面我們來(lái)看看mvc思想架構(gòu)的設(shè)計(jì)

首先打開(kāi).application\controllers\文件目錄,在里面創(chuàng)建一個(gè)student.php控制器:

student.php

在此我們先來(lái)通過(guò)student這個(gè)控制器來(lái)測(cè)試一下,打印出helloworld,記住訪問(wèn)路徑是: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

下面我們來(lái)?yè)Q一下,看看下面這段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);
    }
}

這段代碼需要一個(gè)視圖,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);

包含的是另外一個(gè)視圖文件studen_index.php文件

student_index.php:

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

聯(lián)合輸出:

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

數(shù)據(jù)的CURD

C 控制器

先來(lái)看看數(shù)據(jù)的增加過(guò)程,在student控制器中增加一個(gè)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');
  }
}

更多關(guān)于CodeIgniter相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《codeigniter入門(mén)教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《php優(yōu)秀開(kāi)發(fā)框架總結(jié)》、《ThinkPHP入門(mén)教程》、《ThinkPHP常用方法總結(jié)》、《Zend FrameWork框架入門(mén)教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門(mén)教程》、《php+mysql數(shù)據(jù)庫(kù)操作入門(mén)教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總

希望本文所述對(duì)大家基于CodeIgniter框架的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

肃北| 洪江市| 广宁县| 贞丰县| 永德县| 图片| 合江县| 奉新县| 武冈市| 甘泉县| 林州市| 上林县| 汉源县| 邛崃市| 会同县| 漳浦县| 孝昌县| 团风县| 莒南县| 烟台市| 鄢陵县| 青田县| 浦城县| 四子王旗| 运城市| 交城县| 镇康县| 沂水县| 龙江县| 穆棱市| 武威市| 衡南县| 成安县| 巍山| 攀枝花市| 柘荣县| 逊克县| 师宗县| 塘沽区| 白玉县| 曲周县|