我正在使用CodeIgniter,我的文件夹结构如下所示。
控制器
controllers
-admin
--Access_controller
--more
-website
--Website_controller
--more
模型
Model
-admin
--Access_model
--more here
-website
--Website_model
--more here
视图
view
-admin
--login.php
--changepassword.php
--more here
-website
-- home.php
-- about.php
-- contactus.php
现在我必须访问控制器,但是它不起作用。我检查了SO上的每个帖子,发现了类似的答案。我必须在routes.php文件上添加代码。
我尝试过
1) $config['admin'] = 'admin/Access_controller';
$route['default_controller'] = 'website/Website_controller';
2) $config['admin/Access_controller'] = 'admin';
$config['default_controller'] = 'website/Website_controller';
3) $route['default_controller'] = 'website/Website_controller';
$route['admin/(:any)'] = "admin/$1";
4)另外,我在application-> core中创建了文件My_Route.php并添加了代码,但是该代码仅适用于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.');
}
}
我尝试了所有解决方案,但仍然无法找到错误对象。
该问题的另一种解决方案对我有很大帮助吗?
我不知道我错过了什么。您能帮我解决这个问题吗?