What is the exact Order of execution in yii framework? - yii

What is the exact Order of execution in yii framework?
here, I mean detailed explanation from the moment we enter url in address bar.
How actions in a Controller get executed & when?

If you are talking of basic workflow of yii app then yii definivtive guide can help you.Here is typical workflow taken from the yii definitive guide.
Model-View-Controller (MVC)
If you want the actual workflow of your specific app then you can use logging.

Within a for standard controller, the order of execution for standard methods are:
behaviors,
init,
accessRules,
beforeAction,
Those are the ones I mostly am concerned with.

Enable logging
http://www.yiiframework.com/doc/guide/1.1/en/topics.logging
to see exactly what gets executed and in what order.

If you look at the urlmanager of Yii you will see a bit how it works.
'urlManager' => array(
//somethings
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view', //first rule
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', //second rule
'<controller:\w+>/<action:\w+>' => '<controller>/<action>', //third rule
)
);
After the base url you will have the controller, if the next thing is an integer (<id:\d+>) if will send the request to the view action of the controller. (first rule)
The second rule states that any request with a word and a integer (<action:\w+>/<id:\d+>) will be send to the action with the requested id. For example: http://example/post/update/123 if will be send to the actionUpdate of the PostController with $_GET['id'] == 123.
The third rule is the same as above but with no id. So for example the index and admin action will show a list or a grid with all records

Related

Add CSS in a confide laravel web page

I got some code of Laravel where confide (https://github.com/Zizaco/confide) is used. Now I would like to add CSS in these Web Pages of Laravel.
Can anyone say how can I do that ??
Unless I am mistaken I'm pretty sure the question the poster was trying to ask is how to style the forms that reside outside of the app\viewsfolder. The forms confide uses by default are in the \vendor\zizaco\confide\src\views folder.
You can change the default forms and use custom ones by editing the config.php and style them like any other view.
Change this
*\vendor\zizaco\confide\src\config\config.php
'login_form' => 'confide::login',
'signup_form' => 'confide::signup',
'forgot_password_form' => 'confide::forgot_password',
'reset_password_form' => 'confide::reset_password',
To this
*\vendor\zizaco\confide\src\config\config.php
'login_form' => 'user.login',
'signup_form' => 'user.register',
'forgot_password_form' => 'user.password',
'reset_password_form' => 'user.reset',
I think you misunderstood what confide is or how laravel works.
Confide is a package to manage the authentication process in your website it has nothing to do with the front-end design of your website. It serves the back end operations to authenticate a model.
You must first pass the model through a controller and in to a view.
After that you can use blade templating to present the models and their attributes
and you can use whatever styling you want in your views.
Those are basic principles of the MVC design pattern if you don't understand what I'm trying to explain to you should read the laravel documentation

Yii captcha never passes the validation even if, right letters are in place

This is on my model rules:
array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
This is on my _form:
$this->widget('CCaptcha', array('buttonOptions' => array('class' => 'captcha-anchor')));
On my accessRules:
array('allow','actions'=>array('create','index','view','member', 'captcha'),
'users'=>array('*'),
),
I keep getting,
"The verification code is incorrect"
no matter what I do.
I'm using AjaxValidation with CActiveForm, and wish to keep using it.
Any clue how to fix this?
Please don't post any link, if you happen to know the answer, please describe it, so we can discuss if in need.
Please note that the captcha image is displaying and reloading. No issues there.
Thanks.
I have same problem and it return false every time because :
1- I define Get POST in some base controller and i send a ajax request to home controller which extended from base , because i can not call base controller directly so i change ajax request to current controller not home controller for all pages.
2- I hard coded JQuery in my layout so Yii load two JQuery in the Page so it send 2 request , first verified and second fails, i disabled JQuery auto load helping by this link.

A special application state issue

I am developing a facebook like social networking website using Yii framework. As a logged in user can see profile of any user they got while searching or by other means. in facebook it happens like
facebook.com/marthajoseph/photos
Here the user is viewing the profile of "marthajoseph". Same thing I want to achieve in yii.
Currently I did something like this
myapplication.com/index.php?r=u/default/index?uid=110
Here "u" is a model for users.
Here I am viewing profile of the user with user id "110". The issue is each time I switch the user's photos, profile, posts etc I have to append this uid query string with the url which leads to instability.
How can I achieve the facebook like thing?
I would suggest rewriting the URL completely using the Yii URL Management as mentioned by ernie above
First of all, use path format for the URL. This is done by firstly un-commenting the urlManager lines in protected/config/main.php (around line 34 by default). What this does is let you use "pretty URLs", for example, instead of the URL looking something like this:
www.example.com/index.php?r=user/profile?uid=110
You can have it something like this:
www.example.com/user/110
So, for example, if we wanted to route any URL which has the structure profile/<a users id> to our User Controllers view action (actionView), we could do something like:
'urlManager'=>array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
'user/profile/<id:.+>' => 'user/view',
...
So on the left side of the array we have "what the URL will look like", and on the right we have "where it is pointing". You can then access the id value in your view or in your controller using a $_GET, for example:
echo "You are viewing user id ".$_GET['id'];
You could use this value to query for photos or profile content or whatever associated with that user. In terms of having the users name in the URL (how facebook does it, eg: facebook.com/myusername), you would most likely let the user enter their vanity URL somewhere along the line and store that in the database. You could then change your rule to something like:
'user/profile/<user_vanity_url:.+>' => 'user/view',
And then access that value the same as above using a $_GET. One piece of advice if you go this route is to keep in mind that you should be preventing users from making being able to view content they are not allowed to view, for example, viewing the photos of someone who is not their friend. I would assume you have some sort of table storing these relations?
In regards to having to append the id or whatever value you are passing through the URL, you can simply append it in the view or wherever your HTML is being created, so for example if you want to display a link to the users photos from their profile page you could do something like:
One other thing regarding the URL rules in your urlManager, rules are interpreted from top to bottom, and the first matched rule will be used.
Hopefully this helps you on the right path. Check out the following posts if you are still stuck:
http://yiitutorials.net/easy/easy-url-rewriting-with-yii
Yii basic url rewrite

Yii CAPTCHA url is broken

I want to create an AJAX-registration form on my Yii-project. So on every page I have a login-button, which shows a popup if the user isn't authorized. In that popup he can see registration form with email field, password field, and CAPTCHA (default Yii captcha).
So, my model for user's registration is User. There is a validation rule:
array('code', 'captcha', 'allowEmpty'=>!Yii::app()->user->isGuest),
My controller, where all user's actions are, is User (url: site.url/user/) and I added there captcha action:
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
'foreColor'=>0x000000,
),
In my next code:
$this->widget('CCaptcha', array(
'clickableImage' => true,
'showRefreshButton' => false,
))
And here is a problem:( Being inside a popup, which can be shown on every page (index page, for example, which belongs Main controller) captcha wants to load an image from that controller (from /main/captcha, not /user/captcha).
Adding captcha in every controller is bad idea, so I added
'captchaAction' => '/user/captcha',
But after that captcha wants to load from an url
http://site.loc/user/captcha/v/4fe99aca1bbed
User-friendly url's crashed captcha and I can't avoid it (as I think, not being a yii-expert, it's because of common path-config).
Is there an easy solution to solve this? Should I repair URL's or re-configure CAPTCHA?
So, while I was waiting for help, I solved the problem by myself :)
In my project i separated my controllers into the next hierarchy:
/frontend
/backend
All controllers for common users are (of course) in Frontend section, including UserController and MainController.
Yes, I wrote some configs to hide /frontend/ in URL's like this:
'<c:\w+>/<a:\w+>' => 'frontend/<c>/<a>',
And i was sure, that string in my CAPTCHA config ('captchaAction' => '/user/captcha') knows where to go (and it was almost so!), but NO!
I should write FULL PATH to my controller and action like below:
'captchaAction' => '/frontend/main/captcha',
As I said in question, I placed my CAPTCHA action in UserController, but now you can see it is located in MainController (i deleted it from UserController)
And I got an error:
CCaptchaValidator.action "captcha" is invalid. Unable to find such an action in the current controller.
So, to solve this, I just had to use a property captchaAction of CCaptchaValidator in my User MODEL! Code:
array('code', 'captcha', 'captchaAction'=>'/frontend/main/captcha', 'allowEmpty'=>!Yii::app()->user->isGuest)
So, now my AJAX Captcha validation works correctly where I want.
Good luck with Yii's default CAPTCHA, dear community!

Dispatcher::applyFilter _callable - passing message to redirected page

I followed the tutorial in http://li3.me/docs/manual/lithium-basics/filters.wiki
At the end of the tutorial, if the user is unauthorized, then they get redirected to a login page.
My question: I want to know how to display a message on the login page to explain why they got redirected.
I'm assuming I have to pass my message into the closure, but I'm not sure what to do in the closure itself.
If you need to persist data between 2 requests, write to the Session.
In your case, before redirecting the user to a new location (login page), write to the Session a message (usually just called flash messages).
Session::write('Flash.auth', array('message' => '...'), array('name' => 'default'))
Then on your views, check if the Session is not empty, to display it or not.
Session::read('Flash.auth', array('name' => 'default'))
Since you'll need to do that in many parts of your application, take a look to li3_flash_message plugin, or roll your own