将URL参数传递给APP_CONTROLLER?

时间:2012-01-29 15:28:50

标签: cakephp-1.3

我正在编写我的多级导航元素,来自数据库的数据。当我点击菜单项时,我想将参数传递给APP_CONTROLLER,这对我来说会有些神奇。

如何将URL参数传递给APP_CONTROLLER以获得会影响所有控制器的功能?

网址:http://localhost/controller/function/id:5http://localhost/controller/function/5

如果我尝试像APP这样在APP_CONTROLLER中获取参数

public function beforeFilter(){

$ id = $ this-> params ['id']; }}

public function beforeFilter($ id){

一些代码

}}

我会收到错误消息,例如未定义索引... 缺少AppController :: beforeFilter()的参数1 ...

我是CakePHP的新手,如何做到这一点?或者我有一些基金会设计缺陷?

// Jari

1 个答案:

答案 0 :(得分:0)

第一种选择更好。

app_controller

public function beforeFilter() {
   $id = $this->params['id'];
}

视图

$this->Html->link(__("menu 1",true), array('id'=>'1');

不要忘记添加“parent :: beforeFilter();”在其他控制器的“beforeFilter”内。

我希望你能提供帮助。

相关问题