Hello.
I’m new to Yii Framework. I’m working with 1.0.10 branch.
I’m trying to extend functionality to CWebUser, especyficaly, I’m trying to add a isAdmin and a isRegistered methods. I placed a new class WebUser in /protected/components, which is extending the original CWebUser. Inside, I placed a couple of new public methods, like this:
<?php
/**
* Overload of CWebUser to set some more methods.
*/
class WebUser extends CWebUser
{
public function isAdmin()
{
// When Users are implemented, change this to check roles.
return ( $this->getName() == 'admin' );
}
public function isRegistered()
{
return ( !$this->isGuest() && !$this->isAdmin() );
}
}
Then I added a line in config/main.php to tell Yii to use this new class:
// application components
'components'=>array(
'user'=>array(
// use a customized class, placed in 'components'
'class'=>'WebUser',
Then, I tried to use these new methods in the layout/main.php:
<?php $this->widget('application.components.MainMenu',array(
'items'=>array(
array('label'=>'Backoffice', 'url'=>array('/site/backoffice_main'), 'visible'=>Yii::app()->user->isAdmin),
),
And finally, went to the browser and…
So?
I’ve tried to take off the class param in the config/main.php > components and then the exception says Property “CWebUser.isAdmin” is not defined, so may I understand the new class is being declared?
Did I left any step?
thank you.