another CGridView problem

Hello everyone.

My problem is that when I click another page number all the data from my database table is loaded though when my CGridView is loaded for the first time only those data is loaded that match my search parameters.

Here is my view


$this->widget('zii.widgets.grid.CGridView', array(

	'dataProvider'=>$model->search(),

	'columns'=>array(

		array('name'=>'name','header'=>"Ім'я",'value'=>'htmlspecialchars_decode ($data->name,ENT_QUOTES)'),

		array(   

		'name'=>'dn',

		'value'=>'strtotime($data->dn)?date("d.m.Y",strtotime($data->dn)):""',

		'header'=>'Дата народження'

		),

		array('name'=>'posada','header'=>"Посада"),

		array('name'=>'ppnz','header'=>"Школа",'value'=>'htmlspecialchars_decode($data->ppnz->nazva." ".$data->ppnz->stupin." ".$data->ppnz->nomer_sh,ENT_QUOTES)'),

		array('name'=>'predmet','header'=>"Предмет"),

		array(    

		'class'=>'CButtonColumn',

                'buttons'=>array(

                                'view'=>array('options'=>array('target'=>'_blank')),

                                 'update'=>array('visible'=>'false'),

                                'delete'=>array('visible'=>'false')

                ), ),),

		));

This is my controller


$model = new Ppnz('search');

if(isset($_POST['mysubmit']))

{

  $model->name = $_POST['sname'];

  $model->predmet = $_POST['spredmet'];

  $model->posada = $_POST['sposada'];

  $model->osvita = $_POST['osvita'];

}

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

My Ppnz model


public function search()

{

	$criteria=new CDbCriteria;

	$criteria->with='ppnz';

	$criteria->compare('name',$this->name,true);

	$criteria->compare('posada',$this->posada,true);

	$criteria->compare('osvita',$this->osvita,true);

        $sort = new CSort();

	$sort->attributes = array(

	        'ppnz'=>array(

		'asc'=>'ppnz.nazva',

		'desc'=>'ppnz.nazva desc',

		),

		'name',

		'dn',

		'posada',

		'predmet',

		);

	return new CActiveDataProvider('Ppnz', array(

		'sort'=>$sort,

		'criteria'=>$criteria,

	));

}

What did I do wrong?

Thanks.

In my controller I have:




		if(isset($_GET['Project']))

			$model->attributes=$_GET['Project'];



The search parameters are passed via get, not via post.

Maybe this cause your loss of data.

How do I specify my form action because this


<form method="GET" action="<?php echo Yii::app()->request->baseUrl; ?>/index.php?r=ppnzv/vyvid">

calls my index action, though for method="POST" it works Ok?

Actually it does not call any action. It results in this url


http://localhost/iac1/index.php?srayon=&sname=&spredmet=&ss....


<form method="GET" action="<?php echo CHtml::normalizeUrl('controller/action'); ?>">

Or better:


<?php echo CHtml::beginForm()?>

Check the class reference for parameters of beginForm

Now my problem is solved. Thank you zaccaria for your hints. It really needs to use GET and not POST method.

And CHtml::beginForm() works perfect.

Just one hint for those who want the plain html like I first did: to make it work correct one can remove action="…"

and use r=controller/action as hidden field. But this of course is not Yii way. :)