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?

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.

1 Answer 1


I was able to pass the $username data to the transformer. By doing this:

'transformer' => function(EntryModel $entry) use ($username)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.