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

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

其中:

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');
  }
}

								 
			 
相关文章 大家在看