CakePHP 2.x - 将数据重定向到其他视图

时间:2012-05-13 20:15:55

标签: cakephp cakephp-2.1

如何从控制器向其他视图发送数据?

function index() 
{
    if(!empty($this->data))
    {
                $projects = $this->Hour->getProjectsByDate($this->data);
                **//here I have to redirect $projects to another view.** 
    }
    $this->set('projects', $this->Project->find('list', array('conditions' => 
            array('Project.active' => true)))); 
} 

谢谢! :)

1 个答案:

答案 0 :(得分:2)

尝试在$this->set('projects', $this->Project->find('list', array('conditions' => array('Project.active' => true))));

之后添加此内容

$this->render('whatever view you want');

在渲染不同的视图之前,不要忘记设置变量:

function index() 
{
    if(!empty($this->data))
    {
                $projects = $this->Hour->getProjectsByDate($this->data);
                **//here I have to redirect $projects to another view.**
                  //You should set your variables first before you render a different view: 
              $this->set('projects', $this->Project->find('list', array('conditions' => 
            array('Project.active' => true)))); 

              //Then render a different view
              $this->render('some other view');

    }

}