Refactoring views

Hello. I’m new to Yii and MVC in general. Not new to PHP/MySQL.

I’ve been given the task of refactoring the code-base powering the admin interface of one of our web applications and I’m just after some pointers. The application was written in a bit of a hurry and some of the page-display code has ended up in unexpected places, and it is my job to put this right.

The problem is the main menu. There is a main menu at the top of each page (Home, To Do, Products, News, and Manufacturers). I am writing the "Manufacturer" section, and I added the manufacturer entry to the menu bar in file "<app-root>\themes\classic\views\layouts\main.php" (using the Main Menu widget). The problem is that on some of the sections ("Home" and "To Do"), my new entry is not appearing. The guy who gave me the job mentioned that he "copied and pasted" some code, so I guess these pages are drawing their menu-generation code from more model-specific template areas.

My question is where might he have put such code? Where might Yii be calling it from? I’m sorry that I do not know more about Yii to give more details…

Many thanks,


Usually the main menu’ should be in the layout (views/layout/main.php).

There can be more layouts, you can check in the controllers if the are using different layout, or the menu can simply be replicated in all views.

If is replicated, the best idea is to put in the layout andd to delete from all pages in wich the menu’ has been copied.

Thanks for your help. I’m getting more of a handle on it now. There are a few different page template files with their own menus hard-coded in, and conditional “if($this->id==‘product’)” content - yuck. Some of these are modified “classic” theme files, and some are in the controllers’ view files directories.

According to Yii convention, should the theme directory files be modified, or should I force each controller to look for view files under the protected directory?

EDIT: One more thing: There are two main layouts, one-column and two-column. At the moment they call two different generic page templates, "main.php" and "one-column.php". Is there an easy way of just getting them to call one generic template and specifying the columns elsewhere?

Many thanks,


Found this page. What a great framework!