You are viewing revision #6 of this wiki article.
This is the latest version of this article.
You may want to see the changes made in this revision.
p.s. latest version of this tutorial is always available unter the docs/ folder of the User Management Module.
Installing the User Management Module is very easy due to the great module System of the Yii Framework and the Installer provided by the Module. In this Tutorial we will learn how to use the User Management Module on a fresh created Yii Web Application.
1.) Generate your Webapp:
$ php yii-1.1-dev/framework/yiic webapp testdrive
Create a Web application under '/var/www/testdrive'? [Yes|No] Yes
[...]
Your application has been created successfully under /var/www/testdrive.
2.) Extract the Yii User Management Module under the modules/ directory of your new Web Application. Replace the _0.4 with the latest Version available.
$ cd testdrive/protected
$ mkdir modules
$ cd modules
$ wget http://www.yiiframework.com/extension/yii-user-management/files/User_Management_Module_0.4.tar.bz2
$ tar xvf User_Management_Module_0.4.tar.bz2
3.) Add the Module to your Application Configuration
$ [youreditor] protected/config/main.php
Add this lines:
'modules' => array(
'user' => array(
'debug' => true
),
in your Application Configuration
4.) The Yii User Management Module needs a Database Connection to work. You now have to setup your SQlite or MySQL Database and insert the connection URI in your Application configuration, like this:
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=testdrive',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),
$ mysql -u root localhost
> CREATE DATABASE `testdrive` ;
5.) To let your Web Application use the Authentification Methods of the User Management Module, we need to overwrite the default Authentification Method in the Application Configuration:
'components'=>array(
'User'=>array(
'class' => 'User',
),
'import'=>array(
'application.modules.user.models.*',
This tells our Web Application that is should access the Model 'User' when Yii:app()->User is run. Please note the difference of 'User' and 'user' here. 'User' represents our ActiveRecord-Model while 'user' represents the user configuration.
If you want, you can set the loginUrl of the Application to this:
'user'=>array(
'allowAutoLogin'=>true,
'loginUrl' => array('/user/user/login'),
),
6.) Run the User Management Installer in your Web-Browser:
http://localhost/testdrive/index.php/user/install
7.) Now the Installer of the User Management Module should appear. To the right you can set up alternating Table Names used by the Module. In most cases this is not needed and you can ignore this Settings. If you do change this, be sure to set up the correct table Names in your Application Configuration, so the User Module can access them.
Click 'Install Module':
Congratulations, your User management Module Installation Succeded !
8.) Click on "Administrate your Users (use admin/admin)". Now you are taken to the default Front-End Login-Screen of the User Management Module. Log in with the Username admin and Password admin.
9.) Click on the 'update Icon' (the pencil) of your administrator User. Change the Password to something more safe than 'admin'. Click Save.
10.) Remove the 'debug' => 'true' line from your Application Configuration so your new data doesn't get overwritten accidentally by the installation process.
11.) Update the 'login' link of your Yii Webapp to point to array('user') in the views/layouts/main.php
Configuration of your freshly installed User Management Module:
Language:
The Yii-User Management Module uses the language that is set in the Application Configuration. If you want, you can add a
'language' => 'de',
in your config/main.php to get German Language strings. French and Spain are available, but not every string is translated at the time of this writing.
Role Management:
You can add up new roles in the Role Manager. To check for access to this roles, you can use this code Snippet everywhere in your Yii Application. Most likely it will be used in the ACL Filter of your Controllers:
if(User::hasRole('role'))
{
// user is allowed
}
else
{
// user is not allowed to do this
}
Note, that you can assign several Roles to a user holding your CTRL key in the Listbox. This will be changed to a two-pane view (like in srbac) in a later Version.
available Application Configuration Parameters:
Version number of the Module: ~~~ $version = '0.2'; ~~~ Whether the Module is in Debug mode. ~~~ $debug = false; ~~~ Table Names: ~~~ $usersTable = "users"; $messagesTable = "messages"; $profileFieldsTable = "profile_fields"; $profileTable = "profiles"; $rolesTable = "roles"; $userRoleTable = "user_has_role"; ~~~ Should there be installed the demo Data? : ~~~ $installDemoData = true; ~~~ The Layout used. This is the default Layout of the skeleton App. Replace it with the used layout of your Web Application:
$layout = 'column2';
installation error
wen inplementin all installation steps my brouser is giving following error...
"
CException
CWebUser does not have a method named "isAdmin".
Source File
D:\xampp\htdocs\NewProject\yii-1.1.2.r2086p\yii-1.1.2.r2086\framework\base\CComponent.php(237) ........."
Where is model User defined ?
I think there is something wrong with the following phrase.
This tells our Web Application that is should access the Model 'User' when Yii:app()->User is run.
There is no such model. The model shipped with this module is YumUser and if you set that value the administration area will crash.
Issue with installing User Management Module
I try to installed and followed all instructions but it says
CException
Property "CWebUser.User" is not defined.
During configuration i relied something missing in code
forexampl
'modules' => array(
'user' => array( 'debug' => true ),
it should be
'modules' => array(
'user' => array( 'debug' => true )),
Error 404 Unable to resolve the request "user/install".
When i run this module, i got this error message
errors only
Hello,
is there anybody out there who could at least once make this work? if yes, how?
I get always only errors. please update the tutorial to be able to use it, thanks!
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.