重新映射控制器时使用默认数组
Using a default array when remaping a controller
如何使控制器工作与以下两种方式相同
example.com/page/user1
和 example.com/page/user1/all
public function _remap($slug = "",$params = array("all")){
$sections = array("all","texts","photos");
if ($slug != "" && in_array($params[0],$sections)) {
return $this->router($slug, $params[0]);
}else{
echo "something went wrong";
}
}
但是example.com/page/user1
报错(Undefined offset: 0
)。
我需要在不触及 config/routes.php
的情况下执行此操作
我的快速修复是:
$params[0] = count($params) == 0 ? "all" : $params[0];
你有什么建议吗?
如何使控制器工作与以下两种方式相同
example.com/page/user1
和 example.com/page/user1/all
public function _remap($slug = "",$params = array("all")){
$sections = array("all","texts","photos");
if ($slug != "" && in_array($params[0],$sections)) {
return $this->router($slug, $params[0]);
}else{
echo "something went wrong";
}
}
但是example.com/page/user1
报错(Undefined offset: 0
)。
我需要在不触及 config/routes.php
我的快速修复是:
$params[0] = count($params) == 0 ? "all" : $params[0];
你有什么建议吗?