godhimself
(Godhimself)
December 17, 2012, 8:59am
1
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.
godhimself
(Godhimself)
December 17, 2012, 10:01am
4
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));
}
traprajith
(Traprajith)
December 17, 2012, 10:02am
5
<?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?
traprajith
(Traprajith)
December 17, 2012, 10:03am
6
godhimself:
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?
traprajith
(Traprajith)
December 17, 2012, 10:07am
7
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')); ?>
godhimself
(Godhimself)
December 17, 2012, 10:20am
8
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
traprajith
(Traprajith)
December 17, 2012, 10:29am
9
godhimself:
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.
traprajith
(Traprajith)
December 17, 2012, 10:31am
10
godhimself:
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')); ?>
godhimself
(Godhimself)
December 17, 2012, 10:36am
11
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.