0

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

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)))); 
} 

谢谢!:)

4

1 回答 1

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');

    }

} 
于 2012-05-13T20:41:25.243 回答