Hi,
this is the steps to create web app in yii application.
open terminal:
create one database in phpmyadmin name:mydb;
table:user: uid,uname,password,
-
go thru this path cd/var/www
-
yii\framework\yiic webapp\ myappdemo
-
yes
-
your application is created.
-
open protected/ config/main.php
open it and set
-
now
// uncomment the following to enable the Gii tool
/*
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'Enter Your Password Here',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),
*/
type password for further creation of model & CRUD Generate.
in main .php file
// uncomment the following to use a MySQL database
/*
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=testdrive',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),
*/
in above set your database name ,username,password for database connectivity.
open componenet/useridentity.php file and set this below function
table
in componenet /UserIdentity.php file
public function authenticate()
{
$model=Users::model()->findByAttributes(array('userid'=>$this->username));
if($model != NULL)
{
if($model->password==MD5($this->password))
$this->errorCode=self::ERROR_NONE;
else
$this->errorCode=self::ERROR_PASSWORD_INVALID;
}
else
{
$this->errorCode=self::ERROR_USERNAME_INVALID;
}
return !$this->errorCode;
/*
$users=array(
// username => password
'demo'=>'demo',
'admin'=>'admin',
);
if(!isset($users[$this->username]))
$this->errorCode=self::ERROR_USERNAME_INVALID;
elseif($users[$this->username]!==$this->password)
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
$this->errorCode=self::ERROR_NONE;
return !$this->errorCode;
*/
}
now login with your database is done.
- array(‘label’=>‘User’,‘url’=>array(‘users/admin’)), put this link on views/layout/main.php file. for menu link.