Dear all,
I have a friendship table to record users’ friends.
I have the following columns : sender, receiver, accept.
E.g., If user 1 and user 10 are friends.
The table may be:
sender(1) receiver(10) accept(1)
Or
sender(10) receiver(1) accept(1)
I want to achieve the following effect, so the user can search all his friends, they may be in either sender or receiver field…
Here is what I have now
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->with = array('senderx'); //my relations to the User model.
$criteria->compare('username', $this->friend,true);
$criteria->condition = '(receiver=:uId) OR (sender=:uId)';
$criteria->params = array(
':uId' => Yii::app()->user->id,
);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination'=>array(
'pageSize'=>10,
),
));
}
<?php echo CHtml::link('Search Friends','#',array('class'=>'search-button btn btn-primary')); ?>
<div class="search-form" style="display:none">
<?php $form=$this->beginWidget('CActiveForm', array(
'action'=>Yii::app()->createUrl($this->route),
'method'=>'get',
)); ?>
<div class="row">
<?php echo $form->textField($search,'friend'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Search',array('class'=>'btn btn-success')); ?>
</div>
<?php $this->endWidget(); ?>
All I want is … a default page display user’s friends(either in sender/receiver fields).
You can search the username of the sender/receiver and update the dataprovider…
Any ideas? Big thanks!
Right now it displays all the friends correctly, but the search function is totally useless…