CakePHP在控制器之间传递值

CakePHP在控制器之间传递值,cakephp,cakephp-2.0,Cakephp,Cakephp 2.0,我想将值从一个控制器传递到另一个控制器。 例如,我有一个会议控制器,我想创建一个新的事件。 我想将会议id传递给事件,以确保这两个对象关联。 我想使用beforeFilter方法存储在ivar$会议中 下面是事件控制器中的beforeFilter函数 public function beforeFilter() { parent::beforeFilter(); echo '1 ' + $this->request->id; echo '2 ' +

我想将值从一个控制器传递到另一个控制器。 例如,我有一个会议控制器,我想创建一个新的事件。 我想将会议id传递给事件,以确保这两个对象关联。 我想使用beforeFilter方法存储在ivar$会议中

下面是事件控制器中的beforeFilter函数

public function beforeFilter() {
    parent::beforeFilter();

    echo '1 ' + $this->request->id;
    echo '2 ' +     $this->request['id'];
    echo $this->request->params['id'];
            if(isset(   $this->request->params['id'])){
             $conference_id =   $this->request->params['id'];       
        }
        else{
         echo "Id Doesn't Exist";   
        }   
}
$conferenceId = $this->Session->read('conference_id');
每当我将url更改为以下内容时:

http://localhost:8888/cake/events/id/3

我得到一个错误,说id没有定义


我应该如何进行?

会议
控制器中

$this->Session->write('conference_id', $this->request->id); // or the variable that stores the conference ID
事件中
控制器

public function beforeFilter() {
    parent::beforeFilter();

    echo '1 ' + $this->request->id;
    echo '2 ' +     $this->request['id'];
    echo $this->request->params['id'];
            if(isset(   $this->request->params['id'])){
             $conference_id =   $this->request->params['id'];       
        }
        else{
         echo "Id Doesn't Exist";   
        }   
}
$conferenceId = $this->Session->read('conference_id');
当然,最重要的是你需要

public $components = array('Session'); 

会议
控制器中

$this->Session->write('conference_id', $this->request->id); // or the variable that stores the conference ID
事件中
控制器

public function beforeFilter() {
    parent::beforeFilter();

    echo '1 ' + $this->request->id;
    echo '2 ' +     $this->request['id'];
    echo $this->request->params['id'];
            if(isset(   $this->request->params['id'])){
             $conference_id =   $this->request->params['id'];       
        }
        else{
         echo "Id Doesn't Exist";   
        }   
}
$conferenceId = $this->Session->read('conference_id');
当然,最重要的是你需要

public $components = array('Session'); 

当您通过url传递数据时,您可以通过

$this->passedArgs['variable_name'];
例如,如果您的URL为:

http://localhost/events/id:7
然后用这行代码访问该id

$id = $this->passedArgs['id'];
当您访问通过url接受参数的控制器函数时,您可以像使用任何其他变量一样使用这些参数,例如,您的url如下所示

http://localhost/events/getid/7
那么控制器的功能应该如下所示:

public function getid($id = null){
  // $id would take the value of 7
  // then you can use the $id as you please just like any other variable 
}

当您通过url传递数据时,您可以通过

$this->passedArgs['variable_name'];
例如,如果您的URL为:

http://localhost/events/id:7
然后用这行代码访问该id

$id = $this->passedArgs['id'];
当您访问通过url接受参数的控制器函数时,您可以像使用任何其他变量一样使用这些参数,例如,您的url如下所示

http://localhost/events/getid/7
那么控制器的功能应该如下所示:

public function getid($id = null){
  // $id would take the value of 7
  // then you can use the $id as you please just like any other variable 
}