Answers.Body: <p>I was able to pass the $username data to the transformer. By doing this:</p>
  
  <pre><code>'transformer' =&gt; function(EntryModel $entry) use ($username)
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-13T20:53:33.727Z
Answers.LastActivityDate: 2016-04-15T02:26:58.437Z
Answers.LastEditDate: 2016-04-15T02:26:58.437Z
Answers.UserDisplayName: Sandy D.
Body: <p>The username that is entered in URL. I need to pass this data to my transformer as well since I have an EntryModel combined with a Matrix Field.</p>
  
  <p>My problem is that I have a matrix field where there are multiple matrix blocks. I need to query them based on the user field.</p>
  
  <p>This is added on to my original question: <a href="https://craftcms.stackexchange.com/questions/14546/how-do-i-query-data-using-the-element-api-plugin-based-on-a-custom-field">How do I query data using the Element API Plugin based on a custom field?</a> </p>
  
  <p>I don't know if there is another criteria setting that I could set so that the matrix would only grab the data for the requested user.</p>
  
  <p>My only other idea was to loop through the matrix blocks and check to see if the username requested was equal to the matrix blocks username field. If it is -- then grab the data that I need and set that in a variable to output in the JSON.</p>
  
  <p>However, I can't do this unless I can figure out how to get the username inside the 'transformer'.</p>
  
  <p>Thanks in advance for all the help. I am learning a lot about this plugin and it is an excellent addition to CraftCMS. </p>
  
Tags: <plugins><plugin-elementapi>
Title: How can I pull my Username into the transformer of the ElementAPI plugin?
ThreadText: # How can I pull my Username into the transformer of the ElementAPI plugin?
  
  (Asked by: username_0 on 2016-04-13)
  
  The username that is entered in URL. I need to pass this data to my transformer as well since I have an EntryModel combined with a Matrix Field.
  
  My problem is that I have a matrix field where there are multiple matrix blocks. I need to query them based on the user field.
  
  This is added on to my original question: [How do I query data using the Element API Plugin based on a custom field?](https://craftcms.stackexchange.com/questions/14546/how-do-i-query-data-using-the-element-api-plugin-based-on-a-custom-field)
  
  I don't know if there is another criteria setting that I could set so that the matrix would only grab the data for the requested user.
  
  My only other idea was to loop through the matrix blocks and check to see if the username requested was equal to the matrix blocks username field. If it is -- then grab the data that I need and set that in a variable to output in the JSON.
  
  However, I can't do this unless I can figure out how to get the username inside the 'transformer'.
  
  Thanks in advance for all the help. I am learning a lot about this plugin and it is an excellent addition to CraftCMS.
  
  **Tags:** plugins, plugin-elementapi
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-04-13. Score: 3
  
  I was able to pass the $username data to the transformer. By doing this:
  
  ```
  'transformer' => function(EntryModel $entry) use ($username)
  
  ```
  
  
  ---
  
  