Yii Framework 1.1 Updates, Part 2

February 19, 2010 — 6 Comments
The Yii Book If you like my writing on the Yii framework, you'll love "The Yii Book"!

The latest version of the Yii framework, 1.1, came out in January and has a few significant changes, so I’ve been reviewing my “Learning the Yii Framework” series to make sure it’s all still correct. In a previous post, I made note of the new config bootstrap files for testing purposes, as well as the changes in the auto-generated Views. Here I’m going to look at the Models, Views, and Controllers in more detail.

From my post on Models

The only difference I found is that Yii did a better job of recognizing the relationships between the Department and Employee Models. Specifically, it picked up both relationships: that multiple employees are in a single department and that one employee is the department head. Here’s the relations() method from the Department Model:

public function relations()
{
    return array(
    'deptHead' => array(self::BELONGS_TO, 'Employee', 'deptHeadId'),
    'employees' => array(self::HAS_MANY, 'Employee', 'departmentId'),
    );
}

The Employee Model’s relations() method also reflects both relationships.

From my post on Views

Yii 1.1 has taken a bunch of the best extensions and placed them in their own namespace, zii. A lot of functionality is now added to sites by using widgets from within the zii library. Whereas earlier versions of Yii created a MainMenu component, Yii 1.1 uses the CMenu widget. The default layout also makes use of the CBreadcrumbs widget, include in the zii extensions.

There are a number of View file changes, although none that are dramatic: What was previously the list (list.php) View file is now index (index.php). The index page makes use of a CListView widget to list the records. The admin page makes use of a CGridView widget to display all the records. The show file (show.php) is now called view (view.php). It makes use of the CDetailView widget to show the information for a specific record. Multiple View files can make use of the _view.php script, which is a template for showing an individual record. Every view file identifies breadcrumb information at the top, which will tie into the CBreadcrumbs widget referenced in the main layout file. I’ll try to write up using the breadcrumbs widget at a later time.

From my post on Controllers

No major changes here. The $defaultAction line is no longer present. Also, the names of some of two of the action methods have changed to match the new names of the corresponding View files: actionView() and actionIndex().

If you enjoyed this post, then please consider following me using your favorite social media, the RSS feed, and/or by subscribing to my newsletter. Or go crazy, and buy one or more of my books . Thanks!