【问题标题】:CakePHP get dispatch dataCakePHP 获取调度数据
【发布时间】:2011-11-15 06:57:35
【问题描述】:

我正在使用以下过程将数据设置为 another_view 操作。但我无法获取发送数据。

$this->autoRender = false; 
$dis = new Dispatcher(); 
$dis->dispatch( 
    array("controller" => "users", "action" => "another_view"), 
    array("data" => $user) 
);  

如何从another_view 获取$user 数据? 请帮忙,谢谢。

【问题讨论】:

    标签: cakephp


    【解决方案1】:

    如何创建一个两个方法都可以调用并将数据作为参数传递的函数。

    class Users extends AppController{
    
       function another_view(){
           ...
           $this->_myFunction($this->data);
       }
    
       function _myFunction($data = array()){
           ... //do something with the data
       }
    }
    
    class AnotherModel extends AppController{
       function index(){
          App::import('Controller', 'Users');
          $Users = new UsersController;
          $Users->constructClasses();
          $Users->_myFunction($myData);
       }
    }
    

    不过.. 最好if you put it in the model(如果可能的话)

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多