I don't understand what $this->friend is for ... do you want to search friends by their name?

$criteria->compare('username', $this->friend,true);

What the above means is that you are comparing "friend" with the user's own name ... It's very natural that you get no results (zero records) when you input some name other than the user's own name.

I want the user input either sender or receiver's name in the field, basically, the user input a name in the field, I determine that among all friends of the users,(receiver/sender = :uid), whose username is the user's input.

For example, in my database:

sender:1 receiver:2

sender:5 receiver:1

For user1, his friends are 2 and 5. I want him enter a name and find 2 or 5...

I can't have 2 fields and let user input your friend is receiver or sender...I want the server to decide...

friend is simply a property i declared in my model, its not a column of my table... And now i get ALL results no matter what i input for the friends field. not zero...

By using 'compare', you can forget the params of the criteria. Of course you can use addCondition method instead.
Sometimes you have to merge multiple criteria when your conditions involve complicated 'AND's and 'OR's.
Please look up 'compare', 'mergeWith' in the reference for details.

By using 'compare', you can forget the params of the criteria. Of course you can use addCondition method instead.
Sometimes you have to merge multiple criteria when your conditions involve complicated 'AND's and 'OR's.
Please look up 'compare', 'mergeWith' in the reference for details.