当数据传递到控制器中时,数据和函数名传递到URL
localhost/project/course/Web-Development上面的示例course是控制器的函数名,但将其删除并传递此URL
localhost/project/Web-Development发布于 2019-06-08 21:04:47
使用remap函数可以解决这个问题。
控制器中的代码
public function _remap($method, $params = array())
{
if ($method == 'autocomplete') {
return call_user_func_array(array($this, $method), $params);
} else {
$methodcall = $this->M_tl_admin->Validate_Web($method);
if ($methodcall == 'course') //***course is your function name***
return call_user_func_array(array($this, $methodcall), array($method));
}
}模型中的代码
public function Validate_Web($alias)
{
$res = $this->db->get_where('category', array('ctg_url' => $alias))->result_array();//category is table name and ctg_url is data pass in URL(Web-Development)
if(count($res)>0)
return 'course';
}发布于 2019-06-08 21:11:00
您可以使用路由功能来隐藏函数名称。
https://www.codeigniter.com/user_guide/general/routing.html
$route['product/:any'] = 'project/product_lookhttps://stackoverflow.com/questions/56506532
复制相似问题