CDbCriteria addSearchCondition LIKE%

Hi guys,

I’ve a question.

When I use


$criteria->addSearchCondition('name',$_GET['name']);

it uses the LIKE in this way (suppose that $_GET[‘name’] is equal to “example”)


SELECT .. FROM .. WHERE name LIKE '%example%'

But if want it o be only


LIKE 'example%'

Or


'%example'

how can I do?

thank you

$criteria->addSearchCondition(‘name’,’%’.$_GET[‘name’], false);

Last param is boolean $escape, whether the keyword should be escaped if it contains characters % or _.

Please check

http://www.yiiframework.com/doc/api/1.1/CDbCriteria#addSearchCondition-detail

And there is also the method ‘compare’ which is just below in the documentation.

Set ‘partialMatch’ to true, or set $escape to false [partialMatch is preferable in principle].

http://www.yiiframework.com/doc/api/1.1/CDbCriteria#compare-detail