CakePHP View including other views

后端 未结 7 2169
盖世英雄少女心
盖世英雄少女心 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:38

    Simply use:

    .ctp'); ?>
    

    in the .ctp your action ends up in.

    For example, build an archived function

    function archived() {
      // do some stuff
      // you can even hook the index() function
      $myscope = array("archived = 1");
      $this->index($myscope);
      // coming back, so the archived view will be launched
      $this->set("is_archived", true); // e.g. use this in your index.ctp for customization
    }
    

    Possibly adjust your index action:

    function index($scope = array()) {
      // ...
      $this->set(items, $this->paginate($scope));
    }
    

    Your archive.ctp will be:

    
    

    Ideal reuse of code of controller actions and views.

提交回复
热议问题