everything works fine but the filter is not working.
I modified my controllers’ actionCreate like:-
public function actionCreate()
{
$model=new Principalcomments;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Principalcomments']))
{
$model->attributes=$_POST['Principalcomments'];
if($model->save())
$this->refresh();
// $this->redirect(array('view','id'=>$model->commentId));
}
$model=new Principalcomments('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Principalcomments']))
$model->attributes=$_GET['Principalcomments'];
$this->render('create',array(
'model'=>$model,
));
}
Still this doesnt work, can someone please help me put it right…
I am a beginner too so this could probably be answered better by someone with more experience. Is CGridView used for a create view? I have used it with the index and admin views but I thought you use Active Form for those views.
One for the CGridView … it serves as a container of search parameters.
And the other for the creation form.
public function actionCreate()
{
// model for the form
$model_f=new Principalcomments;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model_f);
if(isset($_POST['Principalcomments']))
{
$model_f->attributes=$_POST['Principalcomments'];
if($model_f->save())
$this->refresh();
}
// model for the grid
$model_g=new Principalcomments('search');
$model_g->unsetAttributes(); // clear any default values
if(isset($_GET['Principalcomments']))
$model_g->attributes=$_GET['Principalcomments'];
$this->render('create',array(
'model_f'=>$model_f,
'model_g'=>$model_g,
));
}
And use $model_f for the form and $model_g for the grid.
I changed the code as you said, but i got a "PHP notice - undefined variable model" on my create view.
I changed the code to render model_g and avoided the notice, but as far as i understand both model instances (model_g and model_f) will have be rendered. isnt that so?
‘$model_g’ and ‘$model_f’ are just the examples. You can use whatever names you like.
But the point is that you have to distinguish the 2 models in your view.
$form = $this->beginWidget('CActiveForm', ...);
echo $form->textBox($model_f, 'name', $options); // have to use the model for the form
...
$this->widget('CGridView', array(
'dataProvider' => $model_g->search(), // have to use the model for the grid
...