Undefined Variable: Model Loginform In Main-View

Moin,

ich moechte direkt in dem main-view ein Formular zum einloggen anzeigen lassen, bekomme aber

stets Undefined variable: model. Binde ich den gleichen Code in meinen index-view ist alles ok.


<?php $form=$this->beginWidget('CActiveForm', array(


	'id'=>'login-form',


	'enableClientValidation'=>true,


	'clientOptions'=>array(


		'validateOnSubmit'=>true,


	),


)); 


<?php echo $form->textField($model,'username',array('class'=>'labelinside', 'value'=>'Username', 'size'=>'30')); ?>



Stehe da grad auf dem Schlauch.

post ur login action

Beitrag ur Aktion login

This is the default action generated by yiic.


	/**

	 * Displays the login page

	 */

	public function actionLogin()

	{

		$model=new LoginForm;


		// if it is ajax validation request

		if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')

		{

			echo CActiveForm::validate($model);

			Yii::app()->end();

		}


		// collect user input data

		if(isset($_POST['LoginForm']))

		{

			$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));

	}




<?php $form=$this->beginWidget('CActiveForm', array(


        'id'=>'login-form',


        'enableClientValidation'=>true,


        'clientOptions'=>array(


                'validateOnSubmit'=>true,


        ),


)); 


$model = new LoginForm


<?php echo $form->textField($model,'username',array('class'=>'labelinside', 'value'=>'Username', 'size'=>'30')); ?>

and , where you are trying to post it ?

und, wenn Sie versuchen, es zu veröffentlichen?

this login form will work,

because ‘model’=>$model is passing to it

$this->render(‘login’,array(‘model’=>$model));

did u got my point?

i think u r doing with the layouts/main?

right?

so use like this




<?php $form=$this->beginWidget('CActiveForm', array(


        'id'=>'login-form',


        'action'=>'site/login' // Note this


        'enableClientValidation'=>true,


        'clientOptions'=>array(


                'validateOnSubmit'=>true,


        ),


)); 


$model = new LoginForm


<?php echo $form->textField($model,'username',array('class'=>'labelinside', 'value'=>'Username', 'size'=>'30')); ?>



no, thats not the point. i have changed my site controller and the form

is displayed. but what i need is that the form will be generated at first inside the main.php.

thx for your efforts

u mean at layouts/main.php?

thats what im trying to tell.

in your main.php

use like this




<?php $form=$this->beginWidget('CActiveForm', array(


        'id'=>'login-form',


        'action'=>'site/login' // Note this


        'enableClientValidation'=>true,


        'clientOptions'=>array(


                'validateOnSubmit'=>true,


        ),


)); 


$model = new LoginForm


<?php echo $form->textField($model,'username',array('class'=>'labelinside', 'value'=>'Username', 'size'=>'30')); ?>



thx a lot, that solves the prob.

:)