[SOLVED] view or site?


I’m pretty new to Yii (my second day ;) ) and I’m about to port my Zend page over to Yii because I like some features better. But I have a problem in understanding a concept.

When I create a controller it also creates a /view/controllerId/index.php. And I want to use this index.php to show my content but I can only load the /view/site/index.php.

For example: I have a website with different views (home, about, news, etc) each backed by a controller of the same name that handles stuff between the view and the model. At least this is how I’ve learned MVC and always used it.

But I can somehow only trigger the SiteController actions. Why is this the case?

What is the difference in Yii between the /view/site/index.php and /view/controllerId/index.php? What goes where? And how can I tell the system that when the “about” link is clicked it calls the indexAction of the AboutController? Or is this wrong and I have to use the SiteController for everything? Then it wouldn’t be that effective.

I hope you can help me? Thanks in advance.



Hi Stefan, welcome to the forum. :)

I think the first and the biggest stumbling block for every newcomer to Yii, is the "urlManager". Yeah, it really was the case for me.

Try the following to access your "about" page.


It should bring you to the “index” action of the “about” controller, if you haven’t touched the configurations for the url manager.

Note that "site" controller is set as the "default" controller of the yii application when you generate it with yiic. And the "index" action is set as the "default" action of the "site" controller.

There’s a few things that I can recommend from my own experience.

Have fun! :)


thx this was the link I was searching for. Building the links with


works :)

The only thing (which I find a bit weird but maybe it’s okay or you have a different suggestion) is that I have to do a


to redirect from the SiteControllers indexAction to my default view.

The reason is that I do not know if i should change the default controller?

I mean is there a reason not to change the default controller? In the end it’s just a controller the system defaults to, isn’t it?

So normally it shouldn’t be a problem to place my custom errorAction to my HomeController and it will use the controllerId/error.php as a view, if I make the HomeController the default Controller?



The default controller is set in the application configuration file, ‘/protected/config/main.php’.

And the error handler is also configured to use ‘site/error’. (This is not the default of Yii, but yiic has done it like this.)

return array(


	'name'=>'my site',

	'language' => 'ja',

	'defaultController' => 'site',  // this is it.





			// use 'site/error' action to display errors




You can change them, of course. :)

See the "Application" section of the guide.



thx alot I think I got it now. Now I feel a bit silly for asking this question because I read the “definitve guide” but skipped the Application and the url part because I thought they are not important because I had specific things in mind I wanted to do. :blink: Well, better read it all first :rolleyes:

Now I can do it as granular as I like to. And I think I will even create a separate ErrorController. It’s cleaner that way