[Solved] Concept of Controller

So, last question for today ;)

I’m still working on to understand some concepts of yii.

I added some additional menu points.

In the ‘pages’ submenu we will find the static pages => ok

Now I want to add an dynamic page.

There a two possibiliteis:

  1. add an action to the site controller

  2. add a new controller (e.g. via gii)

Which I should use in what kind of cases ?

Thy again


The third possibility would be to study the blog sample which ‘ships with’ Yii.

In essence, controllers are linked to models which again are linked to database tables.

But they are not always directly linked to one another.

In most cases the URL follows this pattern:


See the Definitive Guide:


Thank you for your answer.

I always read this chapter, but maybe I didn’t understand it …

I understand the MVC well, so link between controller - model - database table too.

I always use a seperate controller class like described in the yii guide (possibility 2).

But I also read the following:

"Writing class-based actions, we can organize an application in a modular fashion. For example, the following directory structure may be used to organize the code for controllers:"

May be, not must.

However, I desided to generate a controller class for every database table. Hope that fits with the "spirit" of yii and

helps me later to upgrade to yii 2.0 very easy …

Thanks again


Yes, and no. :)

Not all models needs to have a controller.

It depends on how they’re used.

For example, my Project controller has a Project model and performs operations on my ProjectMember model (which doesn’t have a controller of it’s own).

It depends on what controller you will want to perform actions with and using what.

There’s no harm in generating controller, though.

Maybe you’ll refactor them away when you develop you application realising you’re not using them.

Just try some stuff, and you’ll get the hang of it. ;)