im new in yii framework and i want to create a view for a action that use two
model
this is my controller :
public function actionMoneyRequest()
{
// important
// farz kardam money request meghdare hesabe fardo etebare uno dare az avval @author Masoud
if(isset($_POST['id']))
{
$model=UserMoneyrequest::model()->findByAttributes(array('userid'=>$this->User()->id,'accountnumberid'=>$_post['id']));
if(isset($_POST['UserMoneyrequest']))
{
if($_POST['amount']<=$model->amount)
{
$model->amount=($model->amount-$_POST['amount']);
$model->save();
}
else
{
unset($_POST);
Yii::app()->user->setFlash('message', 'موجودی حساب کافی نمیباشد.');
$this->redirect(array(
'user/moneyrequest'
));
}
}
$this->render('moneyrequest',array(
'model'=>$model));
}
else
{
$accountnumber=UserAccountnumber::model()->findAllByAttributes(array('userid'=>$this->User()->id));
$this->render('moneyrequest',array(
'model'=>$accountnumber
));
}
}
at first user have to select his accountnumber from a dropdown list and when he select his Desired account the view show's the selected account information and ...
and this is my view:
<?php
$form=$this->beginWidget('CActiveForm', array(
'id'=>'login-form',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
'htmlOptions'=>array(
'class'=>'js-validation-login form-horizontal push-30-t push-50',
)
));
// var_dump($model); exit;
// var_dump($_POST); exit;
//$options = array ('12' => 'Twelve', '10' => 'Ten');
echo $form->dropDownList('useraccountnumber','',array($model->attributes));
$this->endWidget();
?>
but i got this error:
Fatal error: Call to a member function hasErrors() on a non-object in C:\wamp\www\yii\framework\web\helpers\CHtml.php on line 1985
why i got this error ???
and when i change this below line:
echo $form->dropDownList('useraccountnumber','',array());
to:
echo CHtml::dropDownList('useraccountnumber','',array($model->attributes));
there is no error but i cant see model attributes in dropdown list
how i can to solve this problem and totally how can i use dropdown list with
define $form?
i know i have so many mistakes
thanks everyone for help