CakePHP View including other views

后端 未结 7 2333
盖世英雄少女心
盖世英雄少女心 2021-02-07 12:22

I have a CakePHP application that in some moment will show a view with product media (pictures or videos) I want to know if, there is someway to include another view that threat

7条回答
  •  南旧
    南旧 (楼主)
    2021-02-07 12:56

    In the interest of having the information here in case someone stumbles upon this, it is important to note that the solution varies depending on the CakePHP version.

    For CakePHP 1.1

    $this->renderElement('display', array('flag' => 'value'));

    in your view, and then in /app/views/elements/ you can make a file called display.thtml, where $flag will have the value of whatever you pass to it.

    For CakePHP 1.2

    $this->element('display', array('flag' => 'value'));

    in your view, and then in /app/views/elements/ you can make a file called display.ctp, where $flag will have the value of whatever you pass to it.


    In both versions the element will have access to all the data the view has access to + any values you pass to it. Furthermore, as someone pointed out, requestAction() is also an option, but it can take a heavy toll in performance if done without using cache, since it has to go through all the steps a normal action would.

提交回复
热议问题