欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于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)容感興趣的讀者可查看本站專題:《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)文章

  • Laravel重定向,a鏈接跳轉(zhuǎn),控制器跳轉(zhuǎn)示例

    Laravel重定向,a鏈接跳轉(zhuǎn),控制器跳轉(zhuǎn)示例

    今天小編就為大家分享一篇Laravel重定向,a鏈接跳轉(zhuǎn),控制器跳轉(zhuǎn)示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-10-10
  • PHP_SELF,SCRIPT_NAME,REQUEST_URI區(qū)別

    PHP_SELF,SCRIPT_NAME,REQUEST_URI區(qū)別

    這篇文章主要介紹了PHP_SELF,SCRIPT_NAME,REQUEST_URI區(qū)別,需要的朋友可以參考下
    2014-12-12
  • PHP并發(fā)場(chǎng)景的三種解決方案代碼實(shí)例

    PHP并發(fā)場(chǎng)景的三種解決方案代碼實(shí)例

    這篇文章主要介紹了PHP并發(fā)場(chǎng)景的三種解決方案代碼實(shí)例,有對(duì)這方面感興趣的同學(xué)可以借鑒參考下
    2021-02-02
  • Laravel路由中不固定數(shù)量的參數(shù)如何實(shí)現(xiàn)?

    Laravel路由中不固定數(shù)量的參數(shù)如何實(shí)現(xiàn)?

    最近在學(xué)習(xí)laravel的時(shí)候發(fā)現(xiàn)了一個(gè)有趣的地方,下面和大家分享下,這篇文章主要給大家介紹了關(guān)于Laravel路由中不固定數(shù)量的參數(shù)是如何實(shí)現(xiàn)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來(lái)一起看看吧。
    2017-12-12
  • 如何讓CI框架支持service層

    如何讓CI框架支持service層

    本文主要介紹了在controller和model中加一個(gè)業(yè)務(wù)層service,由它來(lái)負(fù)責(zé)業(yè)務(wù)邏輯,封裝好的調(diào)用接口可以被controller復(fù)用,提高了通用的業(yè)務(wù)邏輯的復(fù)用性,設(shè)計(jì)到具體業(yè)務(wù)實(shí)現(xiàn)會(huì)調(diào)用Model的接口。
    2014-10-10
  • main.php

    main.php

    main.php...
    2006-12-12
  • PHP實(shí)現(xiàn)頁(yè)面靜態(tài)化深入講解

    PHP實(shí)現(xiàn)頁(yè)面靜態(tài)化深入講解

    這篇文章主要介紹了PHP實(shí)現(xiàn)頁(yè)面靜態(tài)化深入講解,本文講解的很透徹,有感興趣的同學(xué)可以研究下
    2021-03-03
  • php使用curl發(fā)送json格式數(shù)據(jù)實(shí)例

    php使用curl發(fā)送json格式數(shù)據(jù)實(shí)例

    這篇文章主要介紹了php使用curl發(fā)送json格式數(shù)據(jù)的實(shí)例,大家參考使用吧
    2013-12-12
  • PHP 繪制網(wǎng)站登錄首頁(yè)圖片驗(yàn)證碼

    PHP 繪制網(wǎng)站登錄首頁(yè)圖片驗(yàn)證碼

    幾乎所有的網(wǎng)站登錄頁(yè)都會(huì)有驗(yàn)證碼,驗(yàn)證碼是一種安全保護(hù)機(jī)制,用于防止垃圾注冊(cè)機(jī)大量注冊(cè)用戶賬號(hào)占用服務(wù)器內(nèi)存從而使服務(wù)器癱瘓。接下來(lái)通過(guò)本文給大家介紹PHP 繪制網(wǎng)站登錄首頁(yè)圖片驗(yàn)證碼,需要的朋友參考下
    2016-04-04
  • PHP curl實(shí)現(xiàn)抓取302跳轉(zhuǎn)后頁(yè)面的示例

    PHP curl實(shí)現(xiàn)抓取302跳轉(zhuǎn)后頁(yè)面的示例

    這篇文章主要介紹了PHP curl實(shí)現(xiàn)抓取302跳轉(zhuǎn)后頁(yè)面的示例,主要是對(duì)CURLOPT_CUSTOMREQUEST參數(shù)的運(yùn)用,需要的朋友可以參考下
    2014-07-07

最新評(píng)論