php – 如何在CodeIgniter 3中使用默认控制器路由中的子文件夹[复制]
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – 如何在CodeIgniter 3中使用默认控制器路由中的子文件夹[复制],小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1493字,纯文字阅读大概需要3分钟。
内容图文
参见英文答案 > CodeIgniter Routing Folder Error 2个
在将$route [‘default_controller’]设置为子目录时,它正在工作,但我想在子目录中更改它并且它不起作用.
解决方法:
默认情况下,codeigniter 3将无法在default_route中包含子文件夹
你需要使用MY_Router.php
位于申请表>核心> MY_Router.php
这将使您能够在CI3中的default_controller中使用子文件夹
<?php
class MY_Router extends CI_Router {
protected function _set_default_controller() {
if (empty($this->default_controller)) {
show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.');
}
// Is the method being specified?
if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2) {
$method = 'index';
}
// This is what I added, checks if the class is a directory
if( is_dir(APPPATH.'controllers/'.$class) ) {
// Set the class as the directory
$this->set_directory($class);
// $method is the class
$class = $method;
// Re check for slash if method has been set
if (sscanf($method, '%[^/]/%s', $class, $method) !== 2) {
$method = 'index';
}
}
if ( ! file_exists(APPPATH.'controllers/'.$this->directory.ucfirst($class).'.php')) {
// This will trigger 404 later
return;
}
$this->set_class($class);
$this->set_method($method);
// Assign routed segments, index starting from 1
$this->uri->rsegments = array(
1 => $class,
2 => $method
);
log_message('debug', 'No URI present. Default controller set.');
}
}
那么这应该让你能够做到
$route['default_controller'] = 'subfolder/controller/function';
内容总结
以上是互联网集市为您收集整理的php – 如何在CodeIgniter 3中使用默认控制器路由中的子文件夹[复制]全部内容,希望文章能够帮你解决php – 如何在CodeIgniter 3中使用默认控制器路由中的子文件夹[复制]所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。