I think CDbCriteria might need some useful enhancements for quick shortcuts to certain repetitive tasks - ideally, it should be made extensible, so we can add our own helper methods, and perhaps it could ship with a few built-in extensions…
For example, for substring searches, this does not look good:
if (isset($keyword)) $criteria->mergeWith(array(
'condition' => '`post`.`body` LIKE ' . $db->quoteValue('%'.$keyword.'%')
));
With a shortcut, this could be done much more elegantly:
if (isset($keyword)) $criteria->submatch('`post`.`body`', $keyword);
The simplest solution (and perhaps most in tune with Yii) would be a call-overload, and a public array where you could configure your helper methods - this configuration could be stored statically with your CDbConnection instance to prevent overhead … for example:
$config = array(
...
// application components
'components'=>array(
...
'db'=>array(
'class' => 'CDbConnection',
'schemaCachingDuration' => 3600,
...
'criteriaHelpers' => array(
'MyCriteriaHelpers'=>array(
'myHelperMethod',
'myOtherHelperMethod',
),
),
),
...
),
...
);
In this example, I’m assuming a MyCriteriaHelpers class with two methods.
Any thoughts?