zoukankan      html  css  js  c++  java
  • CI

    1:ci框架是有入口文件的,前端和后台入口文件(index.php,admin.php);里面修改$application_folder = 'application/home';

    2:项目基本都是在application里面的,home(前端)和admin(后台);

    3:home文件夹下的config文件下面的routes.php($route['default_controller'] = 'article';),config.php($config['base_url'] = 'http://localhost/Ci';在上传服务器的时候改为$config['base_url'] = '/';还需要在最后加入时区设置:date_default_timezone_set('PRC');$config['time_zone'] = date_default_timezone_get(););

    注意:Linux系统设置只能识别PRC,// date_default_timezone_set('Asia/ShangHai');不识别Asia/ShangHai,所以设置的时候注意:

    4:controller是写控制器的,注意:

    (1):文件名必须是大写字母开头,如:'Blog.php';文件保存到 application/controllers/ 目录下 
    (2):类名必须以大写字母开头。

    model是写模型的,view是放视图的;

    5:ci框架需要注意的一些细节问题:

    define('IS_POST',strtolower($_SERVER["REQUEST_METHOD"]) == 'post');[自定义设置IS_POST方法]

    $this->load->helper(array('form','url'));[加载辅助函数]
    $this->load->library('session');[加载sessions]
    $this->load->database();[加载连接数据库]

    $this->load->view('article/add')[加载视图]

    6:form表单提交:

    ($this->load->library('form_validation');

    $this->form_validation->set_rules('pname','用户账号','required|max_length[10]');
    $this->form_validation->set_rules('ppwd','密码','required');
    $this->form_validation->set_rules('ypwd','确认密码','required|matches[ppwd]');
    $this->form_validation->set_rules('pemail','邮箱','required|valid_email');
    if($this->form_validation->run()==false){
    $this->load->view('zhuce/index');
    })

    $arr=$this->input->post();[ci框架接受post提交数据]

    7:ci框架加载连接数据库,查询数据:

    ($this->load->database();
    $query=$this->db->get_where('ci_people',array('pname'=>$arr['pname']));
    $res=$query->result();)

    8:路径跳转问题

    echo "<script>window.location.href='".site_url('Zhuce/index')."'</script>";[不加参数跳转]

    echo "<script>window.location.href='".site_url('Zhuce/index/{$uid}')."'</script>";[加参数跳转]

    9:加载模型

    $this->load->model('Zhuce_model');
    $res=$this->Zhuce_model->edit($arr);

    10:ci框架地址栏获取参数

    $aid=$this->uri->segment(3);[1是控制器,2是方法,3是值]

    11:session存储和删除

    $this->session->set_userdata('pname',$val->pname);[存储session];

    $this->session->unset_userdata('plast_login',$val->plast_login);[删除session];

    12:文件上传:

    $arr=$this->input->post();
    //文件上传:
    $config['upload_path']="./public/uploads/";
    $config['allowed_types']='jpg|gif|png|jpeg';
    $config['file_name']=uniqid(time());
    $config['max_size']=1024;
    $config['max_height']=768;
    $config['max_width']=1024;
    $config['overwrite']=FALSE;
    $this->load->library('upload',$config);
    if(!file_exists($config['upload_path'])){
    mkdir($config['upload_path'],0777,true);
    }
    if($this->upload->do_upload('pimg')){//上传表单图片的name名
    $file=$this->upload->data();//返回上传文件信息
    $arr['pimg']=$file['file_name'];
    }else{
    //图片上传失败报错:
    $error=$this->upload->display_errors();
    $error=strip_tags($error);
    echo "<script>alert('".$error."')</script>";
    echo "<script>window.location.href='".site_url('Ziliao/edit')."'</script>";
    }

    13:视图:view

    <font color="red"><?php echo form_error('atitle'); ?></font>[表单报错]

    视图字段截取

    <td class='text-center'><?php if(strlen($val->aabs)>8){
    echo mb_substr($val->aabs,0,8)."...";
    }else{
    echo $val->aabs;
    } ?></td>

  • 相关阅读:
    Android开发切换host应用
    HTTP缓存相关头
    我理解的Android加载器
    Mysql的NULL的一个注意点
    Android的Activity生命周期
    说说jsonp
    PHP的pcntl多进程
    谈谈不换行空格
    关于Java代码优化的44条建议!
    java8 遍历数组的几种方式
  • 原文地址:https://www.cnblogs.com/houdj/p/7927383.html
Copyright © 2011-2022 走看看