1. 多级目录路由
application\core\MY_Router.php
重写_validate_request方法
/**
* Validates the supplied segments. Attempts to determine the path to
* the controller.
*
* @access private
* @param array
* @return array
*/
function _validate_request($segments)
{
if (count($segments) == 0)
{
return $segments;
}
// Does the requested controller exist in the root folder?
if (file_exists(APPPATH.'controllers/'.ucfirst($segments[0]).'.php'))
{
return $segments;
}
// Is the controller in a sub-folder?
if (is_dir(APPPATH.'controllers/'.$segments[0]))
{
$temp = array('dir' => array(), 'path' => APPPATH.'controllers/');
foreach($segments as $k => $v)
{
$temp['path'] .= $v.'/';
if(is_dir($temp['path']))
{
$temp['dir'][] = $v;
unset($segments[$k]);
}
}
$this->set_directory(implode('/', $temp['dir']));
$segments = array_values($segments);
unset($temp);
if (count($segments) > 0)
{
// Does the requested controller exist in the sub-folder?
if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().ucfirst($segments[0]).'.php'))
{
if ( ! empty($this->routes['404_override']))
{
$x = explode('/', $this->routes['404_override']);
$this->set_directory('');
$this->set_class($x[0]);
$this->set_method(isset($x[1]) ? $x[1] : 'index');
return $x;
}
else
{
show_404($this->fetch_directory().$segments[0]);
}
}
}
else
{
// Is the method being specified in the route?
if (strpos($this->default_controller, '/') !== FALSE)
{
$x = explode('/', $this->default_controller);
$this->set_class($x[0]);
$this->set_method($x[1]);
}
else
{
$this->set_class($this->default_controller);
$this->set_method('index');
}
// Does the default controller exist in the sub-folder?
if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.'.php'))
{
$this->directory = '';
return array();
}
}
return $segments;
}
// If we've gotten this far it means that the URI does not correlate to a valid
// controller class. We will now see if there is an override
if ( ! empty($this->routes['404_override']))
{
$x = explode('/', $this->routes['404_override']);
$this->set_class($x[0]);
$this->set_method(isset($x[1]) ? $x[1] : 'index');
return $x;
}
// Nothing else to do at this point but show a 404
show_404($segments[0]);
}
* Validates the supplied segments. Attempts to determine the path to
* the controller.
*
* @access private
* @param array
* @return array
*/
function _validate_request($segments)
{
if (count($segments) == 0)
{
return $segments;
}
// Does the requested controller exist in the root folder?
if (file_exists(APPPATH.'controllers/'.ucfirst($segments[0]).'.php'))
{
return $segments;
}
// Is the controller in a sub-folder?
if (is_dir(APPPATH.'controllers/'.$segments[0]))
{
$temp = array('dir' => array(), 'path' => APPPATH.'controllers/');
foreach($segments as $k => $v)
{
$temp['path'] .= $v.'/';
if(is_dir($temp['path']))
{
$temp['dir'][] = $v;
unset($segments[$k]);
}
}
$this->set_directory(implode('/', $temp['dir']));
$segments = array_values($segments);
unset($temp);
if (count($segments) > 0)
{
// Does the requested controller exist in the sub-folder?
if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().ucfirst($segments[0]).'.php'))
{
if ( ! empty($this->routes['404_override']))
{
$x = explode('/', $this->routes['404_override']);
$this->set_directory('');
$this->set_class($x[0]);
$this->set_method(isset($x[1]) ? $x[1] : 'index');
return $x;
}
else
{
show_404($this->fetch_directory().$segments[0]);
}
}
}
else
{
// Is the method being specified in the route?
if (strpos($this->default_controller, '/') !== FALSE)
{
$x = explode('/', $this->default_controller);
$this->set_class($x[0]);
$this->set_method($x[1]);
}
else
{
$this->set_class($this->default_controller);
$this->set_method('index');
}
// Does the default controller exist in the sub-folder?
if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.'.php'))
{
$this->directory = '';
return array();
}
}
return $segments;
}
// If we've gotten this far it means that the URI does not correlate to a valid
// controller class. We will now see if there is an override
if ( ! empty($this->routes['404_override']))
{
$x = explode('/', $this->routes['404_override']);
$this->set_class($x[0]);
$this->set_method(isset($x[1]) ? $x[1] : 'index');
return $x;
}
// Nothing else to do at this point but show a 404
show_404($segments[0]);
}
2.数据库的读写分离配置
1.将DB.php 在core下面重写
https://github.com/lvren007/ci3db/blob/master/DB.php
相关推荐
9.CI框架学习-实例操作发表文章之CI框架文件上传类与缩略图类使用 10.CI框架学习-实例操作查看文章CI分页类使用与自定义与AR类连贯操作 11.CI框架学习-实例操作CI自带验证码使用与如何扩展自定义类库(验证码) 12.C...
PHP_CI框架分页使用, 欢迎大家学习哦哦哦!
php CI codeigniter此框架适合各种网站,简单易懂,手册比较通俗易懂适合新老手
php的json和数组相互转换,ci框架遇到的一些问题总结,以及图片上传的一些功能
PHP CI框架修改功能 代码详解
CI框架快速开发平PHP应用,快速学习ci框架。
教程名称:兄弟连最新php视频教程CI框架(19集)课程目录:【】兄弟连php视频教程CI框架-大纲【】兄弟连php视频教程CI框架01~04【】兄弟连php视频教程CI框架05~08【】兄弟连php视频教程CI框架09~12【】兄弟连php视频...
PHP开发教程之CI框架. CodeIgniter
介绍 CI框架的基础配置方法,基本的使用方法。
此项目是一个完整的PHP基于CodeIgniter框架的商城实战项目,适合初学CI框架的人来学习。有一定项目经验的人也可以学习。资源比较难得,觉得有帮助就可以下载学习。
CI框架的mongo_db数据库扩展链接文件,有了它,CI框架链接mongo_db不在烦恼!
一个关于框架的基础知识及有关CI学习的一个基础课件,详细讲解了如何学习和使用CI开发项目。
php CI学习框架的笔记,里面有较全的知识要点
ci框架3.1.9,CodeIgniter 是一个小巧但功能强大的 PHP 框架,作为一个简单而“优雅”的工具包,它可以为开发者们建立功能完善的 Web 应用程序。
Apache/Nginx + PHP (5.3 +) + MySQL(5.0 +),内附安装教程
ci登录,注释详细,新手看看很有用处
ci框架详解
本例主要实现在CI框架中像ThinkPHP一样的二级域名解析方式 1. ci_url_rewirte.php 为实现的代码 可将其插入到system/URI.php 即框架URI类的相应地方 2. URI.php 为我实验版本(Version 1.0)的URI类,其他版本应用...