Hi and Happy 2014 to everyone!
I have a little question:
This is part of my model Peoples.
Here we have relations of Peoples with Events 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(
'events'=>array(self::HAS_MANY, 'Events', 'people_id'),
);
}
And search method
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria = new CDbCriteria();
$criteria->alias = 'p';
$criteria->select = "p.*, c.name AS city_name";
$criteria->join = "JOIN tbl_cities AS c ON p.city_id = c.id";
$criteria->addSearchCondition('p.locality', (isset($_GET['search']) ? $_GET['search'] : null), true, 'OR');
$criteria->addSearchCondition('c.name', (isset($_GET['search']) ? $_GET['search'] : null), true, 'OR');
$criteria->order = 'p.id DESC';
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination' => array(
'pageSize' => 20,
'pageVar'=>'page'
)
));
}
Now part of _search view
<div class="form-group">
<div class="col-lg-12">
<input size="24" maxlength="255" class="form-control inline-control" placeholder="People, City, Locality" name="search" id="Peoples_search" type="text" value="<?php echo isset($_GET['search']) ? $_GET['search'] : ''; ?>" />
<?php echo CHtml::submitButton('Search', array('class'=>'btn btn-primary')); ?>
</div>
</div>
<div class="form-group">
<div class="col-lg-12">
<div class="checkbox">
<?php echo CHtml::checkbox('Peoples_not_empty', (isset($_GET['Peoples_not_empty']) ? $_GET['Peoples_not_empty'] : '')); ?>
<?php echo CHtml::label('only Peoples with events', 'Peoples_not_empty'); ?>
</div>
</div>
</div>
My search method works. Now I would add another condition: if checkbox is checked I have to add AND condition with peoples having atleast one event. I’ve not found anything similar on forum.
Anyone can help me?
Thanks!