Rendering controller to a different view in CakePHP

后端 未结 7 1163
长发绾君心
长发绾君心 2021-02-01 16:10

Is there a way to render a controller to a different view then normal? I\'m trying to pass some data from the controller to a non-default view. Meaning my controller is called:<

7条回答
  •  长情又很酷
    2021-02-01 16:45

    I would rather use:

    $this->view = 'file';
    

    because any $this->set('var', $val) you'll have after $this->render('file') will not reach your view.

    In CakePHP 3.x use:

    $this->viewBuilder()->template('file');
    

    Deprecated in CakePHP 3.7. Use this instead (as Kuldeep Choudhary suggested in comments)

    ViewBuilder::setTemplate('file');
    

提交回复
热议问题