带解释的代码:
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));
}