朋友,
我正在开发一个具有一些基本控制器的应用程序,如user
(用于创建和登录(、page
(用于创建、列出(、home
(网站主页(和其他控制器。
我正在使用Code Igniter作为PHP框架,我真的很喜欢它。但作为一个初学者,我有一些问题。。。
当我转到localhost/ci/时,我会重定向到我定义的"主页"。有一个index
方法负责控制此请求,并为用户提供主页面。
好的。但是,当我在域后输入它们的名称时,我希望显示一些页面,例如:要显示的localhost/ci/page,然后控制器应该检查它是否是页面,然后显示其内容。
要显示的localhost/ci/page/page也接受
我怎样才能做到这一点?例如,如果我转到localhost/ci/page/page-to-be-displayed
,它将尝试加载此方法page-to-be-displayed
,并且将触发404错误(因为CI正试图在"页面"控制器中找到具有该名称的方法(
提前感谢
@dit
这是我的.htaccess
RewriteEngine on
RewriteCond $1 !^(index'.php|images|robots'.txt|styles)
RewriteCond $1 !'.(js|css|html?g)$
RewriteRule ^(.*)$ index.php/$1 [L]
您需要使用CodeIgniter Routes。
在您的Route.php 中
$route['page/(:any)'] = "your-controller/$1";
注意:您可以使用(:any),(:num) or regex
另外,不要忘记从config.php文件中删除index.php
。CodeIgniter API Doc