0

CWidgetとCJuiDialogを使用して、ユーザーログインウィジェットを再作成しようとしています。

ログインリンクをクリックすると、ログインフォームでダイアログが開きます。

ウィジェットの例を使用しました。ほとんど理解していますが、この時点で行き詰まりました。コードのこの部分が何を意味するのかわからない:

public function renderContent()
{
    $form=new User;
    if(isset($_POST['user']))
    {
        $form->attributes=$_POST['user'];
        if($form->validate() && $form->login()){
            $url = $this->controller->createUrl('site/index');
            $this->controller->redirect($url);
        }
    }
    $this->render('login',array('form'=>$form));
}
4

3 に答える 3

1

説明付きのコード:

public function renderContent()
{
    // Var to store data sent by client browser
    $form=new User;
    // Check if the post request has defined the user variable
    if(isset($_POST['user']))
    {
        // fill the $form attributes with the values sent by the web form in the post request
        $form->attributes=$_POST['user'];
        // validate the form data and then check if the data is valid to login the user
        // - the validate call is where the framework check if the data is valid
        //   against the model (e.g. user field must be text, not empty...)
        // - the login call is where you should encode your user validation, check for validity against the database or whatever you want
        if($form->validate() && $form->login()){
            // create the url where the client browser is going to be redirected
            $url = $this->controller->createUrl('site/index');
            // render a 302 redirection to the new page
            $this->controller->redirect($url);
        }
    }
    // if the request doesn't contain the 'user' variable, or if the validation/login calls have failed, render again the form. In the case of errors, they'll be shown in the 'errorSummary' section.
    $this->render('login',array('form'=>$form));
}
于 2012-05-28T10:58:21.557 に答える
1
$this->render('login',array('form'=>$form));

この後、component / view / login.phpにlogin.phpという名前のファイルがあり、このようにビューでアクセスできます...

<?php $this->widget('your class name'); ?>
于 2012-05-28T11:02:18.917 に答える
0
public function renderContent()
{
    $form=new User;//create User model
    if(isset($_POST['user']))// process when client submit (login)
    {
        $form->attributes=$_POST['user'];//add attribute from form in client
        if($form->validate() && $form->login()){//validate and check login using User class created in first line of this function
            $url = $this->controller->createUrl('site/index');//create url for redirect after login successfully
            $this->controller->redirect($url);
        }
    }
    $this->render('login',array('form'=>$form));//if it is not in submiting or login fail, we will go this code, it render the login form
}
于 2012-05-30T09:32:44.647 に答える