codesutra, I have the same error now. Can’t see what’s wrong.
My main.php
<?php
// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');
// Define a path alias for the Bootstrap extension as it's used internally.
// In this example we assume that you unzipped the extension under protected/extensions.
Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');
// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'Yii Auth Demo',
'theme'=>'bootstrap', // requires you to copy the theme under your themes directory
// preloading 'log' component
'preload'=>array('log'),
'modules' => array(
'auth'=>array(
'appLayout' => 'webroot.themes.theme.views.layouts.main', // the layout used by the module.
),
'gii'=>array(
'generatorPaths'=>array(
'bootstrap.gii',
),
),
),
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
),
'defaultController'=>'post',
// application components
'components'=>array(
'bootstrap'=>array(
'class'=>'bootstrap.components.Bootstrap',
),
'authManager' => array(
'class'=>'CDbAuthManager',
//'connectionID' => 'db',
'behaviors' => array(
'auth' => array(
'class' => 'auth.components.AuthBehavior',
'admins'=>array('admin','demo','authenticated'), // users with full access
),
),
),
'user'=>array(
'class' => 'auth.components.AuthWebUser',
'admins' => array('admin','demo','authenticated'), // users with full access
// enable cookie-based authentication
//'allowAutoLogin'=>true,
),
/*'db'=>array(
'connectionString' => 'sqlite:protected/data/blog.db',
'tablePrefix' => 'tbl_',
),*/
// uncomment the following to use a MySQL database
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=yii-auth',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'tablePrefix' => '',
),
'errorHandler'=>array(
// use 'site/error' action to display errors
'errorAction'=>'site/error',
),
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'post/<id:\d+>/<title:.*?>'=>'post/view',
'posts/<tag:.*?>'=>'post/index',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
// uncomment the following to show log messages on web pages
/*
array(
'class'=>'CWebLogRoute',
),
*/
),
),
),
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params'=>require(dirname(__FILE__).'/params.php'),
);
UserIdentity.php
<?php
/**
* UserIdentity represents the data needed to identity a user.
* It contains the authentication method that checks if the provided
* data can identity the user.
*/
class UserIdentity extends CUserIdentity
{
private $_id;
/**
* Authenticates a user.
* @return boolean whether authentication succeeds.
*/
public function authenticate()
{
/* @var $user User */
$user = User::model()->find('LOWER(username)=?', array(strtolower($this->username)));
if ($user === null)
$this->errorCode = self::ERROR_USERNAME_INVALID;
else if (!$user->validatePassword($this->password))
$this->errorCode = self::ERROR_PASSWORD_INVALID;
else
{
$this->_id = $user->id;
$this->username = $user->username;
$auth=Yii::app()->authManager;
if(!is_null($user->role)){
if(!$auth->isAssigned($user->role,$this->_id))
{
if($auth->assign($user->role,$this->_id))
{
Yii::app()->authManager->save();
}
}
}
$this->errorCode = self::ERROR_NONE;
}
return $this->errorCode == self::ERROR_NONE;
}
/**
* @return integer the ID of the user record
*/
public function getId()
{
return $this->_id;
}
}
I use database, storing authitems and others…