Hello friends,
I have successfully login as an admin with the database table, the code is as follows…
private $_id;
public function authenticate()
{
$record=AdminUser::model()->findByAttributes(array('username'=>$this->username)); // here I use Email as user name which comes from database
if($record===null)
{
$this->_id='user Null';
$this->errorCode=self::ERROR_USERNAME_INVALID;
}
else if($record->password!==$this->password) // here I compare db password with passwod field
{ $this->_id=$this->username;
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
{
$this->_id=$record['username'];
//$this->setState('title', $record['E_NAME']);
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
}
public function getId() // override Id
{
return $this->_id;
}
admin_register.php
<?php
/* @var $this AdminUserController */
/* @var $model AdminUser */
$this->breadcrumbs=array(
'Admin Users'=>array('index'),
'admin_register',
);
?>
<h1>Register Admin</h1>
<?php $this->renderPartial(’_form’, array(‘model’=>$model)); ?>
AdminUserController.php
public function actionAdmin_register()
{
$model=new AdminUser;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['AdminUser']))
{
$model->attributes=$_POST['AdminUser'];
if($model->save())
$this->redirect(array('view','id'=>$model->admin_id));
}
$this->render('admin_register',array(
'model'=>$model,
));
}
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view','admin_register'),
'users'=>array('@'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('update','admin_register'),
'users'=>array('admin'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete'),
'users'=>array('admin'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
I am not being able to create , update and delete the records, my admin_user table has only 2 records, Please any body tell me ,