0
votes

I have a problem here with cakePHP. I have 4 .ctp view pages that I want to send information to from my controller. These are not static pages, they are actually dynamic pages with user forms where the user can enter informations. I have a situation where I have to send the same array to the 4 different views (because part of each view needs that array to display the same information, in order words, I want to display the same information on 4 different views). I know that normally I'm supposed to have 1 view per controller actions, but this time I don't want to create 4 similar actions for each of my views (because like I said, all I'm doing is sending an array to each of my 4 view files). How do I go about doing this without creating 4 repetitive actions in my controller for my 4 view files. I hope it's clear enough what I'm trying to do here.

thank you

1
How would you be displaying those views? Is this a case where the action is identical, but based on some variable a slightly altered view should be used? Or are the actions completely different, but the views have some common element?deceze
The actions are identical and the views are different. Basically, I'm sending the same array which will be display on different parts of each viewuser765368
If I got you right, may be you should see this link book.cakephp.org/1.3/view/1081/ElementsEhtesham

1 Answers

2
votes

You can simply use one action in the controller and render different views based on some logic:

public function my_action() {
    $this->set('myVar1', ...);
    $this->set('myVar2', ...);
    $this->set('myVar3', ...);

    if (/* something */) {
        $this->render('foo'); // renders my_controller/foo.ctp
    } else if (/* or other */) {
        $this->render('bar');
    } ...
}