Question on login Form

Dear All, I’m new to php and web design, I got a little question on how does Yii link the view with controller’s special action such as actionLogin. Below is the detail description of my question:

In default webapp framework, there is a view file view/site/login.php. In the siteController.php, it calls the render function


so the controller file link the model with the view.

And I visit the page http://localhost/blog/index.php?r=site/login, and view the source code of this page, I found the following code:

[color="#4169E1"]<div class="form">

<form id="login-form" [color="#FF0000"]action="/queue/index.php?r=site/login"[/color] method="post">

&lt;p class=&quot;note&quot;&gt;Fields with &lt;span class=&quot;required&quot;&gt;*&lt;/span&gt; are required.&lt;/p&gt; 

&lt;div class=&quot;row buttons&quot;&gt; 

	&lt;input type=&quot;submit&quot; name=&quot;yt0&quot; value=&quot;Login&quot; /&gt;	&lt;/div&gt; 

</form></div><!-- form -->

&lt;/div&gt;&#60;&#33;-- content --&#62; 

</div> [/color]

however, I didn’t see any code in login.php that designate the default action as login by submit button. How does Yii link the view with specific action?

Could any one help me to answer this question? Thanks a lot.

Hi Yeecho

The render() method of CController calls some other methods to resolve the view file.

See the documentation here:

In your example, the file is loaded from the associated controller’s view path (which I think is probably protected/views/site/login.php)



Dear Crikey, Thanks for your help. But my question is that how does Yii make controller’s login action linked with view’s submit callback.

you see, in the previous post, the form’s submit action will call “http://localhost/queue/index.php?r=site/login” page. But I didn’t find the related code in view/site/login.php file. This file is rendered by siteController->actionLogin method, so I think must Yii did some background work to glue action and view together. I just don’t know how.

Any way, thanks a lot

I found this code piece in CAtiveForm

class CActiveForm extends CWidget



     * @var mixed the form action URL (see {@link CHtml::normalizeUrl} for details about this parameter).

     *[color=&quot;#FF0000&quot;] If not set, the current page URL is used.[/color]


    public &#036;action='';


[color="#0000FF"] public function init()





                    echo CHtml::statefulForm(&#036;this-&gt;action, &#036;this-&gt;method, &#036;this-&gt;htmlOptions);


                    echo CHtml::beginForm(&#036;this-&gt;action, &#036;this-&gt;method, &#036;this-&gt;htmlOptions);



So I guess the default action url is set to form’s submit action response.