【发布时间】:2017-12-04 23:14:22
【问题描述】:
我将以下代码添加到我的所有控制器正在扩展的 MY_Controller 中:
public function _remap($method, $params = array())
{//exit($this->router->fetch_class());
if (array_search($method, $this->private_methods) !== false && !$this->logged_in)
{
$this->session->set_flashdata('message', array(
'message' => 'You must login to access the requested area',
'error' => 1
)
);
redirect('/');
}
else if (method_exists($this, $method))
{
$this->$method($params);
}
else
{
redirect('/');
}
}
正在创建的问题是调用 $this->$method($params) 正在将参数压缩到一个数组中。所以像下面这样的方法会中断:
function some_method($param1, $param2, $param3)
有没有办法将这个数组分解为类似这样的函数的单个项目?
【问题讨论】:
-
那是我的帖子,上面的代码就是基于那个代码。您所指的链接中的代码不会分隔参数,而是将它们作为数组发送。
-
你可能做错了什么。我进行了测试,它正在发送单个参数。创建
Example控制器并测试答案。
标签: codeigniter remap