Yii Framework Forum: Cdbcriteria Not Displaying Any Results - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cdbcriteria Not Displaying Any Results Rate Topic: -----

#1 User is offline   corbeeresearch 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 21-August 10

Posted 27 January 2013 - 07:26 AM

Hi,

this is what I'm trying to pass the search results to ActiveDataProvider, but it doesn't seem to change anything at all. If I use $dataProvider->model, the search results doesn't display, however, if I use 'dataProvider'=>$model->search(), I get blank results

The controller function is
	public function actionSearch()
	{	
		$itemsPerPage = Yii::app()->request->getQuery('ipp','10');
		$model=new Flowbook('search');
		$model->unsetAttributes();  // clear any default values
		$dataProvider = new CActiveDataProvider('Flowbook');                
		if (isset($_GET['Flowbook']))
                {
                     $model->attributes=$_GET['Flowbook'];
                     $dataProvider->model = $model;
                }
        
        $this->render('search',array(
            'model'=>$model,
            'dataProvider'=>$dataProvider,
        	'itemsPerPage'=>$itemsPerPage,
        ));
	}

0

#2 User is offline   corbeeresearch 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 21-August 10

Posted 27 January 2013 - 08:39 AM

Update:

it appears that the search is the one causing the problems, particularly date_received(date from and date until fields), author_id(drop down) and contributor(list box).

What am I doing wrong?

The Form
<div class="row">
		<?php echo $form->label($model,'date_from'); ?>
		<?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
			    'model'=>$model,
				'attribute'=>'date_from',
				// additional javascript options for the date picker plugin
				'options'=>array(					
					'showAnim'=>'fold',
					'showButtonPanel'=>true,
				    'autoSize'=>true,
				    'dateFormat'=>'yy-mm-dd',
				   ),
			));; ?>
	</div>

	<div class="row">
		<?php echo $form->label($model,'date_until'); ?>
		<?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
			    'model'=>$model,
				'attribute'=>'date_until',
				// additional javascript options for the date picker plugin
				'options'=>array(					
					'showAnim'=>'fold',
					'showButtonPanel'=>true,
				    'autoSize'=>true,
				    'dateFormat'=>'yy-mm-dd',
				   ),
			));	?>
		
	</div>

	<div class="row">
		<?php echo $form->label($model,'author_id'); ?>
		<?php echo $form->dropDownList($model,'author_id',User::getAuthors()); ?>
	</div>
	
	<div class="row">
		<?php echo $form->label($model,'contributor'); ?>
		<?php echo $form->listBox($model,'contributor',Flowbook::getContributors(), array('multiple' => 'multiple')); ?>
	</div>


the compare code for model->search()
public function search()
{

		$criteria=new CDbCriteria;
		
		$arTitle = explode(' ', $this->title);
		$count = count($arTitle);	
		for ($i=0; $i < $count; $i++)
			$criteria->addSearchCondition('title', $arTitle[$i], true, 'OR');
			
		if (isset($this->category))
			if ($this->category > 0)
				$criteria->compare('category',$this->category);
				
				
		if (isset($this->date_from))
		   $criteria->compare('date_received','>=:'.strtotime($this->date_from));

		if (isset($this->date_until))
		   $criteria->compare('date_received','<=:'.strtotime($this->date_until));
		
		$arDescription = explode(' ', $this->description);
		$count = count($arDescription);
		for ($i=0; $i < $count; $i++)
			$criteria->addSearchCondition('description', $arDescription[$i], true, 'OR');
			
		$arKeyword = explode(' ', $this->keyword);
		$count = count($arKeyword);
		for ($i=0; $i < $count; $i++)
			$criteria->addSearchCondition('keyword', $arKeyword[$i], true, 'OR');
		
		if (isset($this->author_id))
			if ($this->author_id > 0)
				$criteria->compare('author_id',$this->author_id);
		
		$arContributor = $this->contributor;
		$criteria->addInCondition('contributor', $arContributor);
				
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
}



0

#3 User is offline   corbeeresearch 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 21-August 10

Posted 27 January 2013 - 08:59 AM

nevermind, I discovered that the search must not have ":"
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users