Yii Framework Forum: Undefined Variable: Model Loginform In Main-View - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Undefined Variable: Model Loginform In Main-View Rate Topic: -----

#1 User is offline   godhimself 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 23-November 12
  • Location:Grasberg in Osterholz, Niedersachsen, Deutschland

Posted 17 December 2012 - 03:59 AM

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.
0

#2 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 17 December 2012 - 04:38 AM

post ur login action
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#3 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 17 December 2012 - 04:59 AM

Beitrag ur Aktion login
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#4 User is offline   godhimself 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 23-November 12
  • Location:Grasberg in Osterholz, Niedersachsen, Deutschland

Posted 17 December 2012 - 05:01 AM

View PostRajith R, on 17 December 2012 - 04:38 AM, said:

post ur login action


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

0

#5 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 17 December 2012 - 05:02 AM

<?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?
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#6 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 17 December 2012 - 05:03 AM

View Postgodhimself, on 17 December 2012 - 05:01 AM, said:

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



this login form will work,
because 'model'=>$model is passing to it

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

did u got my point?
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#7 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 17 December 2012 - 05:07 AM

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')); ?>

Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#8 User is offline   godhimself 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 23-November 12
  • Location:Grasberg in Osterholz, Niedersachsen, Deutschland

Posted 17 December 2012 - 05:20 AM

View PostRajith R, on 17 December 2012 - 05:03 AM, said:

this login form will work,
because 'model'=>$model is passing to it

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

did u got my point?


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
0

#9 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 17 December 2012 - 05:29 AM

View Postgodhimself, on 17 December 2012 - 05:20 AM, said:

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.
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#10 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 17 December 2012 - 05:31 AM

View Postgodhimself, on 17 December 2012 - 05:20 AM, said:

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


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')); ?>

Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#11 User is offline   godhimself 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 23-November 12
  • Location:Grasberg in Osterholz, Niedersachsen, Deutschland

Posted 17 December 2012 - 05:36 AM

View PostRajith R, on 17 December 2012 - 05:31 AM, said:

in your main.php

use like this
...
$model = new LoginForm

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


thx a lot, that solves the prob.
0

#12 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 17 December 2012 - 05:38 AM

View Postgodhimself, on 17 December 2012 - 05:36 AM, said:

thx a lot, that solves the prob.


:)
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users