【发布时间】:2015-02-21 13:19:44
【问题描述】:
当我输入我的基本 URL http://localhost/myproject/admin 时,它会不断将我发送到我的权限页面。 http://localhost/myproject/admin 是 base_url()。
我的 core/Controller.php 它的工作原理是它检查是否可以访问控制器,如果不在忽略列表中,则被重定向到权限,否则可以访问页面。
我想知道是否有可能添加我的base_url() 以便它忽略它并让我可以访问它。我不确定在下面的代码中添加它的最佳位置。
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// I am not using MY_Controller works with Controller fine.
class Controller extends CI_Controller {
public function __construct() {
parent::__construct();
$url = $this->uri->segment(1).'/'.$this->uri->segment(2);
if (isset($url)) {
$route = '';
$segment = explode('/', $url);
if (isset($segment[0])) {
$route .= $segment[0];
}
if (isset($segment[1])) {
$route .= '/' . $segment[1];
}
// $route would equal example: common/dashboard
// $segment[0] folder i.e common
// $segment[1] controller
$ignore = array(
'common/dashboard',
'common/login',
'common/forgotten',
'common/reset',
'error/not_found',
'error/permission'
);
if (!in_array($route, $ignore)) {
redirect('permission');
}
}
}
}
【问题讨论】:
-
我已经准备好配置路由和默认控制器了。
-
有更好的方法,比如使用包含所有路由的配置文件的钩子,或使用
_remap()函数。无论如何,您可以将admin/index添加到您的$ignore数组中 -
会更喜欢上面的。因为我还有其他权限会添加到它,除非你可以展示一个关于在钩子中做什么的例子。
-
当然,检查我的答案
-
我确信你已经配置了路由,但是如果你想为特定情况做一些其他的覆盖,路由应该仍然能够使用
(:any)和索引URI参数$1/$2等来实现这一点跨度>
标签: codeigniter codeigniter-routing