所以我有以下控制器函数来添加事件:
public function add($id = null, $year = null, $month = null, $day = null, $service_id = null, $project_id = null){
...
}
在某些情况下,我需要做的是仅传递 id 和 service_id 或 project_id 并跳过年、月和日。我尝试将参数作为空字符串或空值传递,如下所示,但似乎都不起作用。
echo $this->Html->link('Add event', array(
'controller' => 'events',
'action' => 'add',
25, null, null, null, 3, 54
))
任何帮助深表感谢。
最简单的解决方案可能是使用查询参数。 (我倾向于不再使用命名参数,因为 CakePHP 迟早会放弃它们)
View:
echo $this->Html->link(__('add event'), array('controller' => 'events', 'action' => 'add', '?' => array('id' => 123, 'service_id' => 345, ...)));
控制器:
public function add(){
$id = isset($this->request->query['id']) ? $this->request->query['id'] : null;
$year = isset($this->request->query['year']) ? $this->request->query['year'] : null;
$service_id = isset($this->request->query['service_id']) ? $this->request->query['service_id'] : null;
...
}
这样就很容易只拥有一些参数。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)