I am trying to create a form using CFormModel.CFormModel is used for the without database table.form in the form of checkboxlist and textbox.after complete the form and then after submit the form but i found error i.e,
Undefined variable: model .
where is the problem i am not understand.
any help which is appreciated to me…thanks
my code is below…
konapaz
(Konapaz)
November 23, 2012, 9:27am
2
Hi my friend
generally the CFormModel doesn’t has ids, so you can’t use Search::model()->findByPk($id)
You have to extend your Search model by CActiveRecord but it depends by what you want
KonApaz:
Hi my friend
generally the CFormModel doesn’t has ids, so you can’t use Search::model()->findByPk($id)
You have to extend your Search model by CActiveRecord but it depends by what you want
thanks KonApaz
ok,then how to fetch the selected data of the form in to the controller class(actioncreate).
konapaz
(Konapaz)
November 23, 2012, 11:10am
4
$model=new Search;
if(isset($_POST[‘SearchForm’]))
{
$model->attributes=$_POST[‘ContactForm’];
if($model->validate())
{
…you code after validated form’s value
}
}
KonApaz:
$model=new Search;
if(isset($_POST[‘SearchForm’]))
{
$model->attributes=$_POST[‘ContactForm’];
if($model->validate())
{
…you code after validated form’s value
}
}
here is my action create code…
public function actionCreate()
{
$model=new Search;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Search']))
{
$model->attributes=$_POST['Search'];
if ($model->validate())
// $this->redirect(Yii::app()->user->returnUrl);
//$this->redirect($this->route);
$brand=$model->brand;
$OS=$model->OS;
$price=$model->price;
$this->redirect(array('view','id'=>$model->brand,
$model->OS,$model->price));
}
$this->render('_form',array('model'=>$model));
}
in place of
$this->redirect(array(‘view’,‘id’=>$model->brand,
$model->OS,$model->price));
what am i write here in place of id.
actually i am new in yii so i have some problem.
konapaz
(Konapaz)
November 24, 2012, 1:14am
6
It depends what you want to do
the $this->redirect(‘view’,‘id’=>$model->brand)) means
redirection to <currentController>/view&id=<$model->brand)>
passing to the actionView the $id variable with $model->brand
What exactly you want to do?