侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

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

框架(架构)  /  管理员 发布于 7年前   146

本文实例讲述了基于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:

<?php echo $title; ?>  

load->view($include)?>

其中:

this−>load−>view(include);

包含的是另外一个视图文件studen_index.php文件

student_index.php:

Congratulations. Your initial setup is complete!

联合输出:

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

      <?php echo $title;?>        

load->view($include)?>

student_add.php

".$value.":"    echo form_input(array('name'=>$value));    echo "

" } form_submit('','Add'); form_close();?>

update_student.php

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程序设计有所帮助。

您可能感兴趣的文章:

  • php实现仿写CodeIgniter的购物车类
  • Codeigniter购物车类不能添加中文的解决方法
  • CodeIgniter采用config控制的多语言实现根据浏览器语言自动转换功能
  • CI(CodeIgniter)框架中的增删改查操作
  • CodeIgniter启用缓存和清除缓存的方法
  • Codeigniter(CI)框架分页函数及相关知识
  • CodeIgniter辅助函数helper详解
  • Codeigniter注册登录代码示例
  • Codeigniter实现处理用户登录验证后的URL跳转
  • 基于CI(CodeIgniter)框架实现购物车功能的方法


  • 上一条:
    Symfony查询方法实例小结
    下一条:
    使用Codeigniter重写insert的方法(推荐)
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • Filament v3.1版本发布(0个评论)
    • docker + gitea搭建一个git服务器流程步骤(0个评论)
    • websocket的三种架构方式使用优缺点浅析(0个评论)
    • ubuntu20.4系统中宿主机安装nginx服务,docker容器中安装php8.2实现运行laravel10框架网站(0个评论)
    • phpstudy_pro(小皮面板)中安装最新php8.2.9版本流程步骤(0个评论)
    • 近期文章
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2018-05
    • 2020-02
    • 2020-03
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-08
    • 2020-11
    • 2021-03
    • 2021-09
    • 2021-10
    • 2021-11
    • 2022-01
    • 2022-02
    • 2022-03
    • 2022-08
    • 2023-08
    • 2023-10
    • 2023-12
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客