2013-09-14

I would like to share my little experience with Yii to the community in the form of the below small wiki:

I will demonstrate the user login and logout functionality along with validation errors using aweswome Yiiframework. The blog demo supplied with the standard framework download, provides a simple user login/logout functionality to demonstrate the core framework features. We will add some Ajax functions to this to display login form inside a jQuery modal dialog box with login errors if any. I do make use of ajaxSubmitButton( inside CActiveForm) to add ajax code to the submit button, CJuiDialog for modal dialog box. I will also show you how to separate login action(actionLogin in SiteController) into a separate class file(getLogin) that extends CAction, and later use this class as an action dynamically inside any controller. I use a widget class(loginProvider) and its action(GetLogin) for this purpose. I will now show you what modifications need to be done to the demo application:

Create a file named loginProvider.php and place it inside the components directory.

Create a directory named actions inside components directory.

Create the action class with name getLogin.php and place it inside components/actions directory.

Create a file named login.php and place it inside components/views with the following contents:

Go to the main layout(blog/protected/views/layouts/main.php) and apply the following changes in the menu:

Finally, Go to SiteController(/blog/protected/controllers/SiteController) and append 'login.' action inside actions() method. Now, the login action is accessed as '/site/login.GetLogin'

References:
(http://www.yiiframework.com/demos/blog/ "Yii Blog")
[How to get definite widget in controller]
(http://www.yiiframework.com/forum/index.php/topic/18197-how-to-get-definite-widget-in-controller/page__p__89729__hl__widget+a+action+provider+#entry89729 "How to get definite widget in controller")

Show more