【问题标题】:How can I eliminate the controller name in the url via routes in = codeigniter如何通过= codeigniter中的路由消除url中的控制器名称
【发布时间】:2015-01-06 07:10:57
【问题描述】:
【问题讨论】:
标签:
php
.htaccess
codeigniter
routes
【解决方案1】:
这将与您的第一个问题相同
// it will go to my_controller index
$route['my_function'] = 'my_controller';
// you can set specific controller method remove method will go to index.
$route['chomy_functione/(:any)'] = 'my_controller/my_function';
【解决方案2】:
这应该从project_name/application/config/routes.php这个文件中完成。添加一行
$route['url_first/url_second'] = "any_controller_name/function_name";
【解决方案3】:
您可以在控制器中添加方法 _remap()
https://ellislab.com/codeigniter/user-guide/general/controllers.html#remapping
将以下代码放入您的控制器中
/**
* Intercept all calls to this class.
*
* @access private
* @param string
* @param array
* @return boolean
*/
function _remap($method, $params)
{
// If method exists, call that method.
if (method_exists($this, $method) !== false) return call_user_func_array(array($this, $method), $params);
// If method is actually an existing permalink, show permalink's content
if ($this->SomeModel->exists(array('permalink' => $method))) return $this->view($method);
// Non-existing method
show_404();
}