国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

基于Codeigniter框架實現的student信息系統站點動態發布功能詳解

2024-05-04 23:56:11
字體:
來源:轉載
供稿:網友

本文實例講述了基于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 SystemCongratulations. 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框架的PHP程序設計有所幫助。


注:相關教程知識閱讀請移步到PHP教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 林周县| 安顺市| 清水县| 临夏市| 友谊县| 隆回县| 秦皇岛市| 南通市| 阳朔县| 中超| 桦南县| 自治县| 上饶市| 高雄县| 玉屏| 贵南县| 疏附县| 阿尔山市| 阿拉善盟| 库尔勒市| 庆城县| 通榆县| 纳雍县| 和平区| 灵台县| 交城县| 淅川县| 浠水县| 德钦县| 菏泽市| 临高县| 揭东县| 成武县| 泾川县| 长沙市| 甘肃省| 怀仁县| 怀柔区| 台东县| 濮阳县| 海口市|