【问题标题】:Passing URL parameters to APP_CONTROLLER?将 URL 参数传递给 APP_CONTROLLER?
【发布时间】:2012-01-29 15:28:50
【问题描述】:

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

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

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

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

公共函数 beforeFilter() {

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

公共函数 beforeFilter($id) {

一些代码

}}

我会收到类似 Undefined index...Missing argument 1 for AppController::beforeFilter()...

之类的错误消息

我对 CakePHP 还很陌生,如何做到这一点?还是我有一些根本的设计缺陷?

// 贾里

【问题讨论】:

    标签: cakephp-1.3


    【解决方案1】:

    第一个选项更好。

    app_controller

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

    查看

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

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

    希望你能帮忙。

    【讨论】:

      猜你喜欢
      • 2012-10-08
      • 1970-01-01
      • 2011-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多