the question is: how can i put a login form in every page of my website and let the validation happen in the layout itself?
I tried to create a LoginForm model as written in the documentation, i modified the UserIdentity component to check in the database for authentication and i create a form in the layout as below:
In the site/controller i created correctly an actionLogin that perform validation but now i don’t know how can i render messages/error in the login form itself! It’s placed in the layout i mean and the controller can render just its own view and i don’t want to create a login view that duplicate the form, in the login page.
$model->attributes=$_POST['LoginForm'];
// validate user input and redirect to the previous page if valid
if($model->validate() && $model->login())
$this->redirect(Yii::app()->user->returnUrl);
}
// display the login form
$this->render(‘login’,array(‘model’=>$model));
}
As i think it should be, i render a blank “login” view with $model as parameter; this parameter should be evalueted by <?php echo CHtml::errorSummary($model); ?> in the main.php layout file, but it doesn’t happen.
Obviously, if a write the same login form in the login.php view everything goes fine and the messages appear.
Please help me, i Know i probably miss something stupid (it’s the first time i try to do something with yii).
basically all you have to do is to create a new class file under protected/Components and inherit from CPortlet, overwrite one or two methods (like init() or renderContent()) and create a view file under Components/views, which will display the HTML content
see:
/protected/Components/MyPortlet.php
<?php
Yii::import('zii.widgets.CPortlet');
class MyPortlet extends CPortlet{
public function renderContent(){
$this->render('myPortletView',array('myvar'=>'hello!!'));
}
}
?>