How can we display several static pages on Yii ?


Let’s say we have a controller/view called: “Theater”

Inside Theater, we wish to have several static pages about several specific theaters displayed.

Theater index (that for example, can contain a cmenu with links to each specific theater) already suffers influence from main layout.

Also, some Theater index as some general html elements shared with all specific theater pages .

How should we render those specific static pages each time we select a given theater on the menu ?

I’ve read this nice article, still, the question remains.

Thanks in advance

If you want static pages, create a layout with the static content and tell the controller to use it for that particular action.

The main layout will wrap around it.

You can have as many layouts you want. ‘main.php’, ‘column2.php’, ‘some_static_page.php’…

Not sure if I understand your suggestion.

But on this case, that some_static_page.php layout would have the same header, footer, and general structure as main.php, changing only a h1 tag that says (for the sake of the example: "Theater Detail");

If we follow that path, if later we decide to change the layout, we should also change the same things on ‘some_static_page.php’ …

Isn’t a waste to create 10 actions with only: “render()” method running ?

I do accept that perhaps there isn’t any absolutely dry solution but, I just want to make sure that there’s no better way.

My first thought was to somehow use the index.php view and inside, call $this->renderPartial(‘specificTheaterHere’); but I believe this approach doesn’t work, because inside renderPartial we should have a variable, but where should we change that variable ? On the controller perhaps? Even if possible, we still need to create an action for each static page.

What do you say? If you think I didn’t get your answer, can you please elaborate a little bit more?

Thanks again

You don’t need to create an action for each static page you’d like to render.

Check out the site controller which the webapp yii command creates.

It shows one possible way of handling ‘static pages’.

Run the webapp command and see for yourself.

@jacmoe, so in order to this to be perfectly clear to me.


On this theater controller we create a method called actions:

 public function actions() {

            return array(




on app/view/theater/ we will create a new folder called "region" where our static pages should reside;

We should then edit the menu like this:




                        'label'=>'Specifc Theater A',




                      'label'=>'Specific Theater B',




I’m getting:

The requested view "index" was not found.

the url array should be:

array('theater/region/', 'view'=>'nomeofmyfilewithoutextension');


I still am repeating some code along those specific pages. But np.

Thanks for your feedback