Rendering controller to a different view in CakePHP

后端 未结 7 1062
长发绾君心
长发绾君心 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 17:02

    The right way:

    $this -> render('TestView/index');

    As the answer above mentions, you can use $this -> set to pass a variable to the View.

    However, if that doesn't give you what you want. I'm guessing that you also want the action to display another layout (non-default layout). You can try doing $this -> layout = 'layoutname'; (Layouts are in the layout folder, default on is default.ctp).

    Note: CakePHP's controller isn't designed to pass data to a non-view file (like .php). CakePHP's views should be ending with .ctp.

提交回复
热议问题