Is there a simple and safe way to get data from inside an EE add-ons file without having to create a new PHP SQL query to the database?
Example:
Get the member ID from the email address.
I could just do this in PHP, create an SQL query, and pass the email address to the table that matches the ID number for that member table.
Just curious if there is a native API, or model to do this that would be more elegant.
The recommended way would be to use the Models.
In your case, this would be something like
$member = ee('Model')->get('Member')->filter('email', 'someone@somewhere.com')->first();
echo $member->member_id;
You can also make use of (legacy) database class
Many thanks Yuri! 😊
I was actually trying this already (using models), but the documentation does not really have examples for beginners, so I was stuck with this so far while playing around:
$userID = ee('Model')->get('Member')->first();
echo $userid;
Your code is precisely the examples that would be really useful for new comes to EE. I actually searched all search engines. Even StackOverflow and got no results with just searching ee(‘Model’) for some examples on how this is used in EE.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.