Cdbcriteria::compare Comparison Operator

Hi,

I’m looking into the Database API to do a simple like with ActiveRecord, and i read the phpdoc of the CDBCriteria::compare method which say :

So does that means that web user can set himself a specific operator (when code isn’t specifying one) at the beginning of an input so the SQL query will be modified in some ways ?

That behavior seems ugly, another parameter which is not concatenated would be better.

Yes, exactly.

You can see that behavior implemented in gii-generated admin page. The advanced search form and the inline filter of the grid support the operators like ">", "<", ">=", "<=", … etc.

Well, I think it’s simple and convenient both for the advanced users and the programmers, because it doesn’t require extra UI element and additional coding.

Of course we would want to create a sophisticated user-friendly UI that supports optional operators for general users. Then we would have to do some extra coding for the search form. But we can still use "compare()" with a minimum additional code for that case also.




$search_word = "something";

$operator = ">";

...

if ($operator != "")

    $search_word = $operator . $search_word;

$criteria->compare("attribute", $search_word);



Ok, thank you for your help .