You’re probably getting the errors because your view files (views/layouts/*) are referencing public fields defined in Controller.php. By default, a Yii application uses the $breadbrumbs & $menu properties of Controller.php. If you change your controllers to extend CController, your view files will be trying to access properties that don’t exist.
I find extending Controllers especially useful when working with modules. For example, an Admin module.
By default, I’d like all controller actions (view, update delete etc) to be restricted to Admin users. I don’t want to redefine the access control in each Admin controller so I define a parent AdminController - this extends Controller.
Then, in my admin controllers, I extend AdminController - this allows all my controllers access to that functionality we’ve coded - once.
<?php
/**
* AdminController class file.
*
* @author Matt Skelton
* @date 1-Dec-2012
*/
/**
* Provides additional functionality to the Admin controllers. By default it, restricts all
* Admin actions to administrators and builds an admin menu.
*/
class AdminController extends Controller
{
/**
* @return array action filters
*/
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
);
}
/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
return array(
array('allow',
'users' => array('@'),
'expression' => 'Yii::app()->user->isAdmin'
),
array('deny', // deny all users
'users' => array('*'),
),
);
}
....
<?php
class ProductController extends AdminController
{
// Now, I don't need to redefine my accesscontol, but I could if I wanted to
...
Controller.php is implemented as a courtesy to get you started with the basic application. Look at the public fields it exposes and decide if you need them in your application. If the answer is yes, then extend Controller. If the answer is no, then extend CController.
In my case, I did want to use the breadcrumbs and menu so I extended Controller. Hope that makes sense.
http://www.yiiframew…sics.controller
Matt