Answers.Body: <p>You'd do it from PHP nearly idential to how you'd do it from Twig... by passing in the Asset Transform's handle to <a href="https://craftcms.com/classreference/models/AssetFileModel" rel="nofollow">AssetFileModel's</a> <a href="https://craftcms.com/classreference/models/AssetFileModel#getUrl-detail" rel="nofollow"><code>getUrl()</code></a> method.</p>
  
  <p>Twig:</p>
  
  <pre><code>{% set asset = craft.assets.id(1).first() %}
  
  {% if asset %}
      {{ asset.getUrl('myTransform') }}
  {% endif %}
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Asset);
  $criteria-&gt;id = 1;
  $asset = $criteria-&gt;first();
  
  if ($asset)
  {
      $url = $asset-&gt;getUrl('myTransform');
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-27T07:46:02.770Z
Answers.Text: yep thats the way, thank you very much :)
Answers.UserDisplayName: nickGR
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-25T13:59:03.837Z
Answers.Text: How to do the same in Craftcms 3.
Answers.UserDisplayName: inrsaurabh
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-29T08:13:00.370Z
Answers.Text: https://craftcms.stackexchange.com/questions/30264/get-transformed-asset-url-in-controller-of-module-while-using-eager-loading
Answers.UserDisplayName: inrsaurabh
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-26T19:04:21.557Z
Answers.LastActivityDate: 2016-09-26T19:04:21.557Z
Answers.UserDisplayName: Brad Bell
Body: <p>I want to return JSON with some asset URLs, but i want these URLs to be transformed asset URLs.</p>
  
  <p>Is there some way for me to get the asset transformed URL in the controller? Will the assets be automatically transformed or i need to somehow do it manually ?</p>
  
Tags: <image-transforms>
Title: Get transformed asset URL in controller
ThreadText: # Get transformed asset URL in controller
  
  (Asked by: username_0 on 2016-09-26)
  
  I want to return JSON with some asset URLs, but i want these URLs to be transformed asset URLs.
  
  Is there some way for me to get the asset transformed URL in the controller? Will the assets be automatically transformed or i need to somehow do it manually ?
  
  **Tags:** image-transforms
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-09-26. Score: 2 | Accepted answer
  
  You'd do it from PHP nearly idential to how you'd do it from Twig... by passing in the Asset Transform's handle to [AssetFileModel's](https://craftcms.com/classreference/models/AssetFileModel) [`getUrl()`](https://craftcms.com/classreference/models/AssetFileModel#getUrl-detail) method.
  
  Twig:
  
  ```
  {% set asset = craft.assets.id(1).first() %}
  
  {% if asset %}
      {{ asset.getUrl('myTransform') }}
  {% endif %}
  
  ```
  
  PHP:
  
  ```
  $criteria = craft()->elements->getCriteria(ElementType::Asset);
  $criteria->id = 1;
  $asset = $criteria->first();
  
  if ($asset)
  {
      $url = $asset->getUrl('myTransform');
  }
  
  ```
  
  > **Comments:**
  > **username_0**: yep thats the way, thank you very much :)  
  > **username_2**: How to do the same in Craftcms 3.  
  > **username_2**: https://craftcms.stackexchange.com/questions/30264/get-transformed-asset-url-in-controller-of-module-while-using-eager-loading  
  
  ---
  
  