CI

作者: ShutLove | 来源:发表于2018-02-05 16:25 被阅读0次

一、 url中去掉index.php

  1. Apache环境下,在项目目录下新建.htaccess文件,内容设置为
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
  1. 修改项目config目录config.php
$config['index_page'] = "index.php";

修改为

$config['index_page'] = "";

二、引用静态资源路径无需写完整域名

  1. 修改项目config目录config.php中base_url配置项
$config['base_url'] = 'https://www.xxxx.com/yyy'; //这里是你的网站根目录
  1. 在视图文件加载前加入此行代码
<base href="<?php echo base_url();?>"/>

三、ActiveRecord

  1. result_array用来获取查询结果,如果无结果,返回空数组。
  2. 向数据库插入记录时,有时会有这种需求,当符合某种条件的数据存在时,去修改它,不存在时,则新增。
    insert ... on duplicate key update ...
    http://blog.csdn.net/ghsau/article/details/23557915
    如果用ci框架,提供的Active Record类不支持这种语句,需要用一些特殊方法。
    $sql = $this->db->insert_string('table', $data) . "ON DUPLICATE KEY UPDATE field_A=xxx, field_B=yyy";
    $this->db->query($sql);
    $id = $this->db->insert_id();

四、设置访问域名后的默认首页

  1. 在config/routes.php中设置default_controller,比如想指向controller下home目录的index.php,可配置为
$route['default_controller'] = "home/index";

相关文章

网友评论

      本文标题:CI

      本文链接:https://www.haomeiwen.com/subject/aekizxtx.html