Thursday, August 6, 2009

USE OF IF CONDITION IN FIND QUERY IN CONDITION ARRAYIN #CAKEPHP, #BAKERY ALL THING, #MVC

$condition = array();

if($this->data['Comment']['module_name'] == 'news' && $this->data['Comment']['news'] == 'all')
$condition['Comment.content_type'] = $this->data['Comment']['module_name'];
if($this->data['Comment']['module_name'] == 'opinions' && $this->data['Comment']['opinions'] == 'all')
$condition['Comment.content_type'] = $this->data['Comment']['module_name'];
if($this->data['Comment']['module_name'] == 'classifieds' && $this->data['Comment']['classifieds'] == 'all')
$condition['Comment.content_type'] = $this->data['Comment']['module_name'];



than
use find query
$result = $this->Comment->find('all', array('recursive'=> -1,'fields'=>array('*'),'conditions' => array('Comment.created >' => $fromDate,'Comment.created <' => $toDate, $condition)));

1 comment:

  1. kher hay barri kas k tie lagayi hy? Zafar

    ReplyDelete