Is it possible to use the MySQL LIKE directive in an ElementCriteriaModel? In a plugin, I'd like to pull all Assets with filenames starting with a certain string (the $prefix variable, in the below examples).

It's possible to do this with a custom DbCommand:

$results = craft()-&gt;db-&gt;createCommand()
    -&gt;select('assetfiles.*')
    -&gt;from('assetfiles assetfiles')
    -&gt;where(array(
        'like',
        'assetfiles.filename',
        $prefix.'%',
    ))
    -&gt;queryAll();
$assets = AssetFileModel::populateModels($results);


However, I'd like to do this using an ElementCriteriaModel. The below doesn't work:

$assets = craft()-&gt;elements-&gt;getCriteria(ElementType::Asset, array(
    'filename' =&gt; 'LIKE "'.$prefix.'%"',
    'limit' =&gt; null,
))-&gt;find();


In the above example, is the syntax off, or is not possible to use LIKE in an ElementCriteriaModel parameter?
The * wildcard character should do the trick.

c.f. https://craftcms.com/docs/templating/elementcriteriamodel#parameter-value-syntax

$assets = craft()-&gt;elements-&gt;getCriteria(ElementType::Asset, array(
    'filename' =&gt; $prefix.'*',
    'limit' =&gt; null,
))-&gt;find();