我已经阅读了有关URI路由和视图的手册,但并没有点击.
在我的views文件夹中,有一个名为products的子文件夹.其中有一个名为product_view的文件.在我的控制器中,我有:
function index() {
$data['title'] = 'Product Overview';
$data['main_content'] = 'products/product_view';
$this->load->view('templates/main.php', $data);
}
该模板加载页眉视图,页脚视图和导航视图,以及该视图作为主要内容变量.
在我的URI路由中,我有:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| URI ROUTING
| -------------------------------------------------------------------------
| This file lets you re-map URI requests to specific controller functions.
|
| Typically there is a one-to-one relationship between a URL string
| and its corresponding controller class/method. The segments in a
| URL normally follow this pattern:
|
| example.com/class/method/id/
|
| In some instances, however, you may want to remap this relationship
| so that a different class/function is called than the one
| corresponding to the URL.
|
| Please see the user guide for complete details:
|
| http://codeigniter.com/user_guide/general/routing.html
|
| -------------------------------------------------------------------------
| RESERVED ROUTES
| -------------------------------------------------------------------------
|
| There are two reserved routes:
|
| $route['default_controller'] = 'welcome';
|
| This route indicates which controller class should be loaded if the
| URI contains no data. In the above example, the "welcome" class
| would be loaded.
|
| $route['scaffolding_trigger'] = 'scaffolding';
|
| This route lets you set a "secret" word that will trigger the
| scaffolding feature for added security. Note: Scaffolding must be
| enabled in the controller in which you intend to use it. The reserved
| routes must come before any wildcard or regular expression routes.
|
*/
$route['default_controller'] = "index_controller";
$route['laser-configurator'] = "configurator";
$route['news-and-events'] = "news";
$route['products/product-overview'] = "products/product_view";
$route['scaffolding_trigger'] = "";
/* End of file routes.php */
/* Location: ./system/application/config/routes.php */
当我尝试转到domain.com/products/product-overview时,这会导致404错误.我是否需要对.htaccess进行处理?如果是这样,该怎么办?这是我的.htaccess:
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$index.php?/$1 [L,QSA]
非常感谢您提供一些具体的帮助,因为该文档并不专门介绍如何解决此问题.我在论坛上做了一些搜索,但没有看到任何内容,但我一直在发布此消息.
解决方法:
要为您的控制器使用多级目录结构,请使用this post中讨论的路由器扩展,我有时会使用它,并且可以保证它能正常工作.