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!

6 responses to Yii Framework 1.1 Updates, Part 2

  1. Hey Larry,

    I’m new to PHP and going thru both your books (PHP6… & PHP advanced). Just curious what you like about Yii verses say CodeIgnitor. sure that is a loaded question, but does it basically come down to personal perference? Also, as someone still getting their feet wet with PHP should I look into an MVC framework or wait until I have a better understanding of PHP first.

    Thanks,
    Mike

    • I’ve not used CodeIgnitor, so I can’t compare the two, although I’ve heard good things about CodeIgnitor. Yes, I think the choice of framework is almost entirely personal preference. What do you value and which framework best meets those values? For me, the first consideration, which did rule out lots of frameworks, was that I wanted it to be written for PHP 5. There weren’t that many other critical features for me, although Yii’s default integration with jQuery was pretty big. I don’t worry too much about benchmarks, because you probably can’t trust them too much. The next issue is documentation: how good is it? I think Yii does pretty good with this, or at least it tries too.

      As for PHP and frameworks, you really need to have a decent understanding of PHP in order to make the required changes and tweaks. Otherwise you’ll be lost on several levels, in my opinion. But try it for yourself and see what you think!

  2. “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.”
    Can more?

  3. How Larry.
    I created my nice css and jquery active menus.
    How can I insert my page url within the href=” ” which is within the
    Here is example

    Home

    I tried to use CHtml menu, but I lose my active menu

Comments are great, but I'd strongly prefer any requests for assistance get made in the support forums. Thanks!