Yii Framework Forum: How To Filter Data In Cgridview When Records Get From Different Models - Yii Framework Forum

Jump to content

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

How To Filter Data In Cgridview When Records Get From Different Models filter data in cgridview when records get from different Models Rate Topic: -----

#1 User is offline   sprymanish 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 07-June 12

  Posted 07 February 2013 - 06:27 AM

Here Is my Code:

Controller:


class ProductController extends Controller
{


....
/**
* Manages all Skus.
*/
public function actionAdmin()
{

$uid = Yii::app()->user->getId();
if($uid != 1){
$value = ComSpry::getUnserilizedata($uid);
if(empty($value) || !isset($value)){
throw new CHttpException(403,'You are not authorized to perform this action.');
}
if(!in_array(1, $value)){
throw new CHttpException(403,'You are not authorized to perform this action.');
}
}
$image-new Skuimages;
$model=new Sku('search');

$model->unsetAttributes(); // clear any default values
if(isset($_GET['Sku']))
$model->attributes=$_GET['Sku'];
$imageUrl=$image->imageThumbUrl;
$this->render('admin',array(
'model'=>$model,
'skuimages'=>$imageUrl
));

}

}
}


MOdel:


public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.

$criteria=new CDbCriteria;
if(!empty($this->met_not_less)){
$criteria->condition="totmetalwei > :met_not_less";
$criteria->params[':met_not_less']=$this->met_not_less;
}
if(!empty($this->met_not_more)){
$criteria->condition="totmetalwei < :met_not_more ";
$criteria->params[':met_not_more']=$this->met_not_more;
}
$criteria->compare('idsku',$this->idsku);
$criteria->compare('skucode',$this->skucode,true);
$criteria->compare('tdnum',$this->tdnum,true);
$criteria->compare('cdate',$this->cdate,true);
$criteria->compare('mdate',$this->mdate,true);
$criteria->compare('updby',$this->updby);
$criteria->compare('leadtime',$this->leadtime);
$criteria->compare('refpo',$this->refpo);
$criteria->compare('parentsku',$this->parentsku);
$criteria->compare('parentrel',$this->parentrel,true);
$criteria->compare('taxcode',$this->taxcode,true);
$criteria->compare('dimunit',$this->dimunit,true);
$criteria->compare('dimdia',$this->dimdia,true);
$criteria->compare('dimhei',$this->dimhei,true);
$criteria->compare('dimwid',$this->dimwid,true);
$criteria->compare('dimlen',$this->dimlen,true);
$criteria->compare('totmetalwei',$this->totmetalwei,true);
$criteria->compare('metweiunit',$this->metweiunit,true);
$criteria->compare('totstowei',$this->totstowei,true);
$criteria->compare('stoweiunit',$this->stoweiunit,true);
$criteria->compare('numstones',$this->numstones);
$criteria->compare('grosswt',$this->grosswt);

if(!empty($this->type)) $criteria->with[] = 'skucontent';
if(!empty($this->gemstone)) $criteria->with[] = 'stones';
if(!empty($this->gem_shape)) $criteria->with[] = 'shapes';
if(!empty($this->gem_size)) $criteria->with[] = 'sizes';
if(!empty($this->type) || !empty($this->gemstone) || !empty($this->gem_shape) || !empty($this->gem_size)) $criteria->together = true;

if(!empty($this->type)) $criteria->compare( 'skucontent.type', $this->type, true );
if(!empty($this->gemstone)) $criteria->compare('stones.namevar',$this->gemstone, true);
if(!empty($this->gem_shape)) $criteria->compare('shapes.name',$this->gem_shape, true);
if(!empty($this->gem_size)) $criteria->compare('sizes.size',$this->gem_size, true);
if(!empty($this->sku_size)) $criteria->compare( 'skucontent.size', $this->sku_size, true );

return new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
));
}


Views:


In the view, I am getting ajax error when I search shape with size and stone name.


Many Thanks....

Attached File  error.JPG (31.73K)
Number of downloads: 25
0

#2 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,483
  • Joined: 04-March 10
  • Location:UK

Posted 07 February 2013 - 06:41 AM

Can you show the rest of the response? The content of the exception message should tell you what's gone wrong.
0

#3 User is offline   sprymanish 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 07-June 12

  Posted 07 February 2013 - 07:25 AM

View PostKeith, on 07 February 2013 - 06:41 AM, said:

Can you show the rest of the response? The content of the exception message should tell you what's gone wrong.


Thanks for your replying, Please send me the solution.

Many Thanks.
Attached File  error2.JPG (148.17K)
Number of downloads: 18
0

#4 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,483
  • Joined: 04-March 10
  • Location:UK

Posted 07 February 2013 - 07:31 AM

That's still not showing the exception details. You'll need to capture the response in your browser's developer tools.

If you're using chrome, go to Tools -> Developer Tools, then click on the network tab.

Run your filter request again and you should see an extra line appear in the network table, which will probably be red because an exception was thrown.

Click the row in the left hand cell, then choose the Response tab.

Paste everything in there into here.
0

#5 User is offline   sprymanish 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 07-June 12

Posted 07 February 2013 - 07:38 AM

View PostKeith, on 07 February 2013 - 07:31 AM, said:

That's still not showing the exception details. You'll need to capture the response in your browser's developer tools.

If you're using chrome, go to Tools -> Developer Tools, then click on the network tab.

Run your filter request again and you should see an extra line appear in the network table, which will probably be red because an exception was thrown.

Click the row in the left hand cell, then choose the Response tab.

Paste everything in there into here.


Thanks So much in advance.

Please check the attached snap.

Attached File  error3.jpg (177.47K)
Number of downloads: 18
0

#6 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,483
  • Joined: 04-March 10
  • Location:UK

Posted 07 February 2013 - 07:51 AM

For some reason tbl_stone is being joined twice with the same alias. Something might be wrong with your relations. Can you post the relations for the base model here?
0

#7 User is offline   sprymanish 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 07-June 12

Posted 07 February 2013 - 11:06 PM

View PostKeith, on 07 February 2013 - 07:51 AM, said:

For some reason tbl_stone is being joined twice with the same alias. Something might be wrong with your relations. Can you post the relations for the base model here?

hii Keith, Thanks for your suggestion, Here is my code of model:

public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'iddept0' => array(self::BELONGS_TO, 'Dept', 'iddept'),
'idpo0' => array(self::BELONGS_TO, 'Po', 'idpo'),
'refrcvd0' => array(self::BELONGS_TO, 'Dept', 'refrcvd'),
'refsent0' => array(self::BELONGS_TO, 'Dept', 'refsent'),
'idstone0' => array(self::BELONGS_TO, 'Stone', 'idstone'),

'sizes' => array(self::HAS_MANY, 'Stonesize', array('idstonesize'=>'idstonesize'), 'through'=>'idstone0'),
'shapes' => array(self::HAS_MANY, 'Shape', array('idshape'=>'idshape'), 'through'=>'idstone0'),
'iduser0' => array(self::BELONGS_TO, 'User', 'updby'),
);
}
0

#8 User is offline   sprymanish 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 07-June 12

Posted 07 February 2013 - 11:39 PM

View PostKeith, on 07 February 2013 - 07:51 AM, said:

For some reason tbl_stone is being joined twice with the same alias. Something might be wrong with your relations. Can you post the relations for the base model here?


Hey Keith, You are the Masterman in yii..

Many Thanks, My problem is solved.
0

#9 User is offline   jkofsky 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 527
  • Joined: 17-May 10
  • Location:Pensacola, Florida

Posted 10 February 2013 - 09:32 PM

And the answer is??????
Do, or do not. There is no 'try.' Jedi Master Yoda
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