zoukankan      html  css  js  c++  java
  • CodeIgniter 应用开发笔记 2

    一个简单的例子

    我们通过一个例子来说明使用CI是多么简单的事情!

    我们首先下载一个IBM开发者网站上的一个例子来做移植。

    下载地址:http://www.ibm.com/developerworks/web/library/wa-codeigniter/

    我们开始吧!

    基类

    在使用老版本的CI的时候,我们要变更一下基类的名称。

      

    序号

    老版本(V1.6.2)

    新版本(V2.1.3)

    备注

    1

    Controller

    CI_Controller

    2

    Model

    CI_Model

        在新版本中已经更改了默认的构造器。

    比如,老版本中在每个继承类的第一段都有:

           function 类名(){

                  parent::Model();

           }

       或

    function 类名(){

                  parent::Controller();

           }

        新版本都由两个下划线和construct为构造器名

    function __construct(){

                  parent::__construct();

           }

    XSS过滤器

    在config目录下的config.php中:

    $config['global_xss_filtering'] = FALSE;

    更改为

    $config['global_xss_filtering'] = TRUE;

    函数更改:

    把“input”变更为“security”

    $this->input->xss_clean

    成为

    $this->security->xss_clean

    我们的“仓库”

    首先,填写位于config文件夹的database.php中的用户名、密码、数据库名等

    $db['default']['username']= 'root';

    $db['default']['password']= 'qazxsw';

    $db['default']['database']= 'carnumber';

    然后,创建数据表

    CREATE TABLEcontacts (

      id int NOT NULL AUTO_INCREMENT,

      name varchar(128) NOT NULL,

      email varchar(255) NOT NULL,

      notes text NOT NULL,

      stamp timestamp NOT NULL defaultCURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,

      ipaddress varchar(32) NOT NULL,

      PRIMARY KEY (id))AUTO_INCREMENT=100001;

    最后,我们在model中编写代码即可:

    functionaddContact(){

          $now= date("Y-m-d H:i:s");

           $data = array(

                  'name' =>$this->security->xss_clean($this->input->post('name')),

                  'email' =>$this->security->xss_clean($this->input->post('email')),

                  'notes' =>$this->security->xss_clean($this->input->post('notes')),

                  'ipaddress' =>$this->input->ip_address(),

                  'stamp' => $now

          

           );

           $this->db->insert('contacts',$data);

     }

     实现的效果,如下图:


  • 相关阅读:
    使用FileReader在浏览器读取预览文件(image和txt)
    移动端Vue图片获取,压缩,预览组件-upload-img(H5+获取照片,压缩,预览)
    文件(图片)转base64
    Vue单页面应用打包app处理返回按钮
    hbuilder/hbuilderx 无法检测到模拟器
    不启动AndroidStudio直接启动其模拟器
    ES6,箭头函数 (=>)注意点
    ES6,扩展运算符
    strcmp使用注意
    android11 gc5035前置摄像头当作后置使用左右镜像问题
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3003774.html
Copyright © 2011-2022 走看看