Property "CWebUser.isAdmin" is not defined - ERROR MESSSAGE

Hi,

Thanks for the code.

I’m a Yii newbie and downloaded your code and followed your instructions and installed in a fresh testdrive yii application.

The install worked fine. I got to the congratulations page which told me to login using admin/admin as the username and pwd.

The problem:

I’m getting an error message when i try to login using admin/admin.

Here’s the full error message and below my config/main.php

Any help is very much appreciated, many thanks!!

best,

bartes

Error:

CException

Description

Property "CWebUser.isAdmin" is not defined.

Source File

/Applications/MAMP/htdocs/yii/framework/web/auth/CWebUser.php(108)

00096: /**

00097: * PHP magic method.

00098: * This method is overriden so that persistent states can be accessed like properties.

00099: * @param string property name

00100: * @return mixed property value

00101: * @since 1.0.3

00102: */

00103: public function __get($name)

00104: {

00105: if($this->hasState($name))

00106: return $this->getState($name);

00107: else

00108: return parent::__get($name);

00109: }

00110:

00111: /**

00112: * PHP magic method.

00113: * This method is overriden so that persistent states can be set like properties.

00114: * @param string property name

00115: * @param mixed property value

00116: * @since 1.0.3

00117: */

00118: public function __set($name,$value)

00119: {

00120: if($this->hasState($name))

Stack Trace

#0 /Applications/MAMP/htdocs/yii/framework/web/auth/CWebUser.php(108): CComponent->__get(‘isAdmin’)

#1 /Applications/MAMP/htdocs/yii/framework/base/CComponent.php(264): CWebUser->__get(‘isAdmin’)

#2 [internal function]: CComponent->__call(‘isAdmin’, Array)

#3 /Applications/MAMP/htdocs/yii/framework/base/CComponent.php(616) : eval()'d code(1): CWebUser->isAdmin()

#4 /Applications/MAMP/htdocs/yii/framework/base/CComponent.php(616): eval()

#5 /Applications/MAMP/htdocs/yii/framework/web/auth/CAccessControlFilter.php(337): CComponent->evaluateExpression(‘Yii::app()->use…’, Array)

#6 /Applications/MAMP/htdocs/yii/framework/web/auth/CAccessControlFilter.php(240): CAccessRule->isExpressionMatched(Object(CWebUser))

#7 /Applications/MAMP/htdocs/yii/framework/web/auth/CAccessControlFilter.php(111): CAccessRule->isUserAllowed(Object(CWebUser), Object(YumUserController), Object(CInlineAction), ‘::1’, ‘GET’)

#8 /Applications/MAMP/htdocs/yii/framework/web/filters/CFilter.php(39): CAccessControlFilter->preFilter(Object(CFilterChain))

#9 /Applications/MAMP/htdocs/yii/framework/web/CController.php(1049): CFilter->filter(Object(CFilterChain))

#10 /Applications/MAMP/htdocs/yii/framework/web/filters/CInlineFilter.php(59): CController->filterAccessControl(Object(CFilterChain))

#11 /Applications/MAMP/htdocs/yii/framework/web/filters/CFilterChain.php(130): CInlineFilter->filter(Object(CFilterChain))

#12 /Applications/MAMP/htdocs/yii/framework/web/CController.php(283): CFilterChain->run()

#13 /Applications/MAMP/htdocs/yii/framework/web/CController.php(257): CController->runActionWithFilters(Object(CInlineAction), Array)

#14 /Applications/MAMP/htdocs/yii/framework/web/CWebApplication.php(324): CController->run(‘adminpanel’)

#15 /Applications/MAMP/htdocs/yii/framework/web/CWebApplication.php(121): CWebApplication->runController(‘user/user/admin…’)

#16 /Applications/MAMP/htdocs/yii/framework/base/CApplication.php(135): CWebApplication->processRequest()

#17 /Applications/MAMP/htdocs/testdrive/index.php(13): CApplication->run()

#18 {main}

config/main.php:

<?php

// uncomment the following to define a path alias

// Yii::setPathOfAlias(‘local’,‘path/to/local-folder’);

// This is the main Web application configuration. Any writable

// CWebApplication properties can be configured here.

return array(

'basePath'=&gt;dirname(__FILE__).DIRECTORY_SEPARATOR.'..',


'name'=&gt;'My Web Application',





// preloading 'log' component


'preload'=&gt;array('log'),





// autoloading model and component classes


'import'=&gt;array(


	'application.models.*',


	'application.components.*',


	'application.modules.user.models.*',


),





/*


'modules'=&gt;array(


	// uncomment the following to enable the Gii tool


	


	'gii'=&gt;array(


		'class'=&gt;'system.gii.GiiModule',


		'password'=&gt;'Enter Your Password Here',


	),


	


),


*/





'modules' =&gt; array(


	'user' =&gt; array(


		'modules' =&gt; array(


			'role',


			'profiles',


			'messages',


			),


  'debug' =&gt; true,


		)


	),








// application components


'components'=&gt;array(


	'user'=&gt;array(


		// enable cookie-based authentication


		'allowAutoLogin'=&gt;true,


		'loginUrl' =&gt; array('/user/user/login'),


	),


	// uncomment the following to enable URLs in path-format


	/*


	'urlManager'=&gt;array(


		'urlFormat'=&gt;'path',


		'rules'=&gt;array(


			'&lt;controller:&#092;w+&gt;/&lt;id:&#092;d+&gt;'=&gt;'&lt;controller&gt;/view',


			'&lt;controller:&#092;w+&gt;/&lt;action:&#092;w+&gt;/&lt;id:&#092;d+&gt;'=&gt;'&lt;controller&gt;/&lt;action&gt;',


			'&lt;controller:&#092;w+&gt;/&lt;action:&#092;w+&gt;'=&gt;'&lt;controller&gt;/&lt;action&gt;',


		),


	),


	*/


	/*'db'=&gt;array(


		'connectionString' =&gt; 'sqlite:'.dirname(__FILE__).'/&#46;&#46;/data/testdrive.db',


	),*/


	// uncomment the following to use a MySQL database


	


	'db'=&gt;array(


		'connectionString' =&gt; 'mysql:host=localhost;dbname=testdrive',


		'emulatePrepare' =&gt; true,


		'username' =&gt; 'root',


		'password' =&gt; 'root',


		'charset' =&gt; 'utf8',


		'tablePrefix' =&gt; '',


	),


	


	'errorHandler'=&gt;array(


		// use 'site/error' action to display errors


        'errorAction'=&gt;'site/error',


    ),


	'log'=&gt;array(


		'class'=&gt;'CLogRouter',


		'routes'=&gt;array(


			array(


				'class'=&gt;'CFileLogRoute',


				'levels'=&gt;'error, warning',


			),


			// uncomment the following to show log messages on web pages


			/*


			array(


				'class'=&gt;'CWebLogRoute',


			),


			*/


		),


	),


),





// application-level parameters that can be accessed


// using Yii::app()-&gt;params['paramName']


'params'=&gt;array(


	// this is used in contact page


	'adminEmail'=&gt;'webmaster@example.com',


),

);

This is because yii dont have a function named isAdmin in the Framework is you want a fast solution but a litlle unsafe you can use this “Yii::app()->user->name == ‘admin’”

This only check if the name of the user is admin.