CI路由规则
请问,,CI路由规则$route['blog/joe'] = "blogs/users/34";
如果URL的前两个分段是"blog"和"joe",那么将会重定向到"blogs"类的"users"方法中处理.并且将ID"34"设为参数.
CI的路由重定向,只能是由类到类
我想实现
隐藏类控制器,只显现方法!
也就是,
$route['blog/joe'] = "joe";
http://localhost:8080/cixy/index.php/blog/joe
变成
http://localhost:8080/cixy/index.php/joe
我想只能扩展路由
但不知道如何做,
高手可否指点一二 :o全部功能都用一个控制器? 中小站点.
有何不可! 这样做可以啊,有什么问题吗?只是要写好正则。 Hex如何写!
可以贴点代码? $route['joe/(:any)'] = "blog/joe/$1";
类似这样的就可以把所有 joe/xxxxx/xxxxxx 都映射到 blog/joe/xxxx/xxxx 了
路由最重要的是正则 很感谢 HEX 的回答,
但我想实现
隐藏当前控制器,只显现方法!
就像
class Contact_us extends Controller{
function index()
{
$data['title'] = 'Home---adress page';
$this->load->view('home_view',$data);
}
function job()
{
$data['title'] = 'Home---info page';
$this->load->view('info_view',$data);
}
function faceback()
{
$data['title'] = 'Home---adress page';
$this->load->view('adress_view',$data);
}
}
访问URL 是
http://localhost:8080/cixy/index.php/contact_us/index
http://localhost:8080/cixy/index.php/contact_us/job
http://localhost:8080/cixy/index.php/contact_us/faceback
我想它变成
http://localhost:8080/cixy/index.php/index
http://localhost:8080/cixy/index.php/job
http://localhost:8080/cixy/index.php/faceback
也就是隐藏当前控制器
就像隐藏index.php那样! 路由只能是一对一的编写,CI 没有隐藏控制器的功能,我想也不可能像隐藏 index.php 那样,因为一个应用不可能只有一个控制器,所以要每个控制器设定一个路由规则,而且不能互相冲突。
如果你的应用只有一个控制器,那完全可以用刚才的路由规则实现。否则就没法隐藏控制器,谁知道你当前的方法是哪个控制器的?
页:
[1]