Hi, I am using phpmaker 2024, need to use Entity classes in userfn.php files using api class, following method/code is working fine but showing empty result. Kindly help me out this that how we can use Entity classes properly in custom code/API’s. my code is as below
Make ensure that i am using this under Api_Action($app) method using API calls. API is working but showing empty results (empty array). any help or support will highly be appreciated.
Thank you for your response, using debug option, its shows only empty array, both $em & $customer objects, also try all possible methods but no success. even use this method $em->getRepository(Entity\Customer::class) and debug, again empty array. I have been searching & going through the help in forum but no success.Also use this method
You may your complete code in userfn.php for discussion. If you tried to use directly in Global Code (not in Api_Action), it won’t work because the container is not built yet. (You should see errors if you have enabled Debug, don’t skip.)
Hi, This is working fine using findAll() and findBy() menthod, its giving records in array but not showing attribute values in table schema like customer name, id, cell and all table attributes. sample code is below that is working fine and giving results as expected. Problem is not giving attribute values. Thank you once again for your help.
If you meant find() does not work, then you may not have set the “customerId” as primary key of your table or you have composite key (which will not work with find()) or the data type of the primary key value you search does not match that of the table, as said above.
No its not such a case. find() method is working fine and other methods too. Its shows array length (records) but don’t show the meta data & values (table columns not appearing). As per the code below it is fetching the matched customer based upon cell number and in response show array length 1. but columns are not appearing in $customer object.
any help or support will highly be appreciated. Thank you once again.
hello,I just tested your code with one of our tables, and it appears it worked - find() returned 4445 rows with all columns and data returned in the array…
but at my end. meta info is not appearing. (columns data). kindly make it run under your code. an API call to fetch the customer based upon cell number. Try at your end & check the result.
Note that findBy() returns array of entities (not array or object). You need to convert entity to array by the entity’s toArray() so you can do json_encode().
Oky but in my code findBy also returning the same array against matched value but not showing the values. sample code share. kindly assist in this regards. moreover, how can i get the connection object in order to initiate the EntityManager($con, $config) in custom files using maker generated code/functions.
All entity repository methods returns entity or array of entities, not assciative array, not stdClass object. You can see the details by, for example, var_dump($customer). As said above, you need to write a little more code to convert entity to array first.
If you just to output records as JSON, there is no need to use entities, simply use ExecuteJson() or ExecuteRows().
“Note that findBy() returns array of entities (not array or object). You need to convert entity to array by the entity’s toArray() so you can do json_encode().”
Also As per your directions this one is working as expected.