I am experiencing some strange behavior with my app’s controllers, and although I’m sure I am missing something obvious here, I cannot see what the problem is.
Here’s the issue: I added a public property called $pageHeading to the Controller class that all of my controllers inherit from by default. By doing this I was hoping to be able to call $this->pageHeading from the main layout file without having to manually add it to each controller in order to avoid an error message (some don’t need it).
Here is my Controller class:
<?php
/**
* Controller is the customized base controller class.
* All controller classes for this application should extend from this base class.
*/
class Controller extends CController
{
/**
* @var string The value that will appear in the <h1> tag in the layout file.
*/
public $pageHeading='';
/**
* @var string the default layout for the controller view. Defaults to 'application.views.layouts.column1',
* meaning using a single column layout. See 'protected/views/layouts/column1.php'.
*/
public $layout='application.views.layouts.column1';
/**
* @var array context menu items. This property will be assigned to {@link CMenu::items}.
*/
public $menu=array();
/**
* @var array the breadcrumbs of the current page. The value of this property will
* be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
* for more details on how to specify this property.
*/
public $breadcrumbs=array();
}
Here is an example from one of the child controllers:
class DegreeController extends Controller
{
public function init()
{
$this->pageHeading = 'blah blah blah';
}
// Non-relevant stuff omitted ...
}
And finally, here is the error message I am getting:
CException
Description
Property "DegreeController.pageHeading" is not defined.
Source File
/some/example/directory/protected/controllers/DegreeController.php(24)
00012: /**
00013: * @return array action filters
00014: */
00015: public function filters()
00016: {
00017: return array(
00018: 'accessControl', // perform access control for CRUD operations
00019: );
00020: }
00021:
00022: public function init()
00023: {
00024: $this->pageHeading = 'blah';
00025: }
00026:
00027: /**
00028: * Specifies the access control rules.
00029: * This method is used by the 'accessControl' filter.
00030: * @return array access control rules
00031: */
00032: public function accessRules()
00033: {
00034: return array(
00035: array('allow', // allow admin user to perform 'admin' and 'delete' actions
00036: 'actions'=>array('index', 'create', 'update'),
Stack Trace
#0 /some/example/directory/protected/controllers/DegreeController.php(24): CComponent->__set('pageHeading', 'blah')
#1 /some/other/directory/yii-1.1.1.r1907/framework/web/CWebApplication.php(319): DegreeController->init()
#2 /some/other/directory/yii-1.1.1.r1907/framework/web/CWebApplication.php(120): CWebApplication->runController('degree/update')
#3 /some/other/directory/yii-1.1.1.r1907/framework/base/CApplication.php(135): CWebApplication->processRequest()
#4 /some/example/directory/index.php(12): CApplication->run()
#5 {main}
Can anyone see what I am missing here? Thanks in advance!