Answers.Body: <p>The <code>*</code> wildcard character should do the trick.</p>
  
  <p>c.f. <a href="https://craftcms.com/docs/templating/elementcriteriamodel#parameter-value-syntax" rel="nofollow">https://craftcms.com/docs/templating/elementcriteriamodel#parameter-value-syntax</a></p>
  
  <pre><code>$assets = craft()-&gt;elements-&gt;getCriteria(ElementType::Asset, array(
      'filename' =&gt; $prefix.'*',
      'limit' =&gt; null,
  ))-&gt;find();
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-01T22:43:09.563Z
Answers.Text: Works like a charm. Thanks Michael! (I edited in a working example)
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-01T22:39:43.547Z
Answers.LastActivityDate: 2016-09-01T22:42:31.363Z
Answers.LastEditDate: 2016-09-01T22:42:31.363Z
Answers.UserDisplayName: Michael Rog
Answers.Body: <p>A possible workaround is to use the <code>search</code> parameter like this:</p>
  
  <pre><code>$assets = craft()-&gt;elements-&gt;getCriteria(ElementType::Asset, array(
      'search' =&gt; 'filename::'.$prefix.'*',
      'limit' =&gt; null,
  ))-&gt;find();
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-01T22:35:54.787Z
Answers.LastActivityDate: 2016-09-01T22:35:54.787Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>In a plugin, I'd like to pull all Assets with filenames starting with a certain string (the <code>$prefix</code> variable, in the below examples).</p>
  
  <p>It's possible to do this with a custom DbCommand:</p>
  
  <pre><code>$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);
  </code></pre>
  
  <p>However, I'd like to do this using an ElementCriteriaModel. The below doesn't work:</p>
  
  <pre><code>$assets = craft()-&gt;elements-&gt;getCriteria(ElementType::Asset, array(
      'filename' =&gt; 'LIKE "'.$prefix.'%"',
      'limit' =&gt; null,
  ))-&gt;find();
  </code></pre>
  
  <p>In the above example, is the syntax off, or is not possible to use LIKE in an ElementCriteriaModel parameter?</p>
  
Tags: <plugin-development><elementcriteriamodel>
Title: Is it possible to use the MySQL LIKE directive in an ElementCriteriaModel?
ThreadText: # Is it possible to use the MySQL LIKE directive in an ElementCriteriaModel?
  
  (Asked by: username_0 on 2016-09-01)
  
  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()->db->createCommand()
      ->select('assetfiles.*')
      ->from('assetfiles assetfiles')
      ->where(array(
          'like',
          'assetfiles.filename',
          $prefix.'%',
      ))
      ->queryAll();
  $assets = AssetFileModel::populateModels($results);
  
  ```
  
  However, I'd like to do this using an ElementCriteriaModel. The below doesn't work:
  
  ```
  $assets = craft()->elements->getCriteria(ElementType::Asset, array(
      'filename' => 'LIKE "'.$prefix.'%"',
      'limit' => null,
  ))->find();
  
  ```
  
  In the above example, is the syntax off, or is not possible to use LIKE in an ElementCriteriaModel parameter?
  
  **Tags:** plugin-development, elementcriteriamodel
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2016-09-01. Score: 2 | Accepted answer
  
  The `*` wildcard character should do the trick.
  
  c.f. <https://craftcms.com/docs/templating/elementcriteriamodel#parameter-value-syntax>
  
  ```
  $assets = craft()->elements->getCriteria(ElementType::Asset, array(
      'filename' => $prefix.'*',
      'limit' => null,
  ))->find();
  
  ```
  
  > **Comments:**
  > **username_0**: Works like a charm. Thanks username_1! (I edited in a working example)  
  
  ---
  
  ### Answer by username_0 on 2016-09-01. Score: 1
  
  A possible workaround is to use the `search` parameter like this:
  
  ```
  $assets = craft()->elements->getCriteria(ElementType::Asset, array(
      'search' => 'filename::'.$prefix.'*',
      'limit' => null,
  ))->find();
  
  ```
  
  
  ---
  
  