Ajax Form Post Confusion

Hi Again,

I’m still very new to yii and poking around in someone else’s code in confusion…

I’m looking at a:

[color="#FF8C00"]protected/view/admin/MySearchFormView.php[/color] file.

Near the top of the file it has a:


<?php $this->renderPartial('_search', array('model' => $model,)); ?>

Which posts results onto the same page into a grid (which is also a form):


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

    'id' => 'my-searchform-grid',

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

    'filter' => $model,

    ... 

    ...



The generated HTML says the form action is:


 action="/index.php/admin/ObjectSearch" 

Unfortunately the results are not what I would expect…

How can I find where these results are being generated from?

Inside:

[color="#FF8C00"]protected/controllers/ObjectSearchController.php[/color]

There appears to be nothing useful.

Inside:

[color="#FF8C00"]protected/models/activerecords/ObjectSearch.php[/color]

There is a:


public function search()

But it doesn’t seem to have the same parameters that I’m searching on.

Advice greatly appreciated!

Thanks!!!

in model, the search() method use a $model ($this) as a filter for search. Here is the place search result returns. And the $model is posted from the _search or Objectsearch view file.

the problem is the dataProvider, remove the ‘all’, in search().

Thanks!

I’m still a bit confused though…

Is there an easy way to see what’s being posted and which function in which file is actually running the search?

Note - I removed the ‘all’ but it didn’t seem to make much different to the search results… It’s still barely returning results.

  1. maybe you had better chage your dataProvider like this:

‘dataProvider’=>$model->search(), //why you use the active()?

  1. what is posted: the $model is posted, to the form action , that is ‘index.php/admin/ObjectSearch’ as your code.

  2. where the search result returns: the form action is a yii route, which means the actionObjectSearch in adminController is called.

so just take a look at what is going on in that action. it probably renders the mySearchFormView and pass the $model into it. Since you didn’t provide the code of this action, i said ‘probably’.

then take a look at mySearchFormView.php to see what is going on next. we can see that is reanders the _search view file and pass a $model into it. also it use a widget to show the search result. the search result is provided by a dataProvider. that is $model->search()

so we take a look at the model file to read search() method. we can find that the search() method use $this (the model itself) as a filter to search. so here is the place search result returns.

Thanks!! You’re really helpful.

Where can I find the documentation on the search? What’s the difference between:


$model->active()->search('all')

,


$model->active()->search()

and


$model->search()

?

Removing the ‘active()’ has allowed one of the search filters to work a little better… So one criteria is searching, but seems to be only ever returning 10 rows. The other search criteria, if set, never returns anything.

This is despite pagination being set to false - where can I specify all rows to be returned?:


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

    'id' => 'my-searchform-grid',

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

    'filter' => $model,

	'enablePagination' => false,

       ...

So the yii controller that’s executed is in AdminController.php:




	public function actionObjectSearch()

	{		

		$model = new Object('search');

		$model->unsetAttributes();


		if (isset($_REQUEST['analysisTypeHidden'])) {

			Yii::app()->user->setState('analysisType',$_REQUEST['analysisTypeHidden']);

			unset($_REQUEST['analysisTypeHidden']);

		}

		else if (isset($_REQUEST['analysisTypeList'])) {

			Yii::app()->user->setState('analysisType',$_REQUEST['analysisTypeList']);

			unset($_REQUEST['analysisTypeList']);

		}		

		else 

		{

			Yii::app()->user->setState('analysisType','1');

		}


		

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

		{

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

		}

		else 

		{

			$this->saveDetails($_POST);

			$this->saveAnalysis($_POST);

			if (Yii::app()->request->isAjaxRequest)

			{

				echo 'Save successful';

				Yii::app()->end();

			}			

		}

		

		//$this->setPageSize();

		$data = array();

		$data['model'] = $model;

		

		$this->render('mySearchForm',$data);

	}

the $model->search() is generated by Gii, as a result, there is no documentation for it. Luckly, there is only several lines of code in it. and very easy to understand.




public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('id',$this->id);

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

		$criteria->compare('user_id',Yii::app()->user->id);


		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

	}



BESIDES, i CAN’T find the documentation for $model()->active() either. Could you please provide it for me. Thanks.