We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

call service vs dao | Forum

Marcus Nov 29 '19

What is the difference between these:



This goes directly yo DAO Function:




public function checkRecords($idList) {
        return $this->testDao->checkRecords($idList);


Which is better?

Patricia Zorrilla Leader
Patricia Zorrilla Nov 29 '19

It is exactly the same because Smarty is used, and after being precompiled there are no "jumps" from one function to another. You can check it by examining the PHP code generated by Smarty.

However, for elegance, and for possible future versions, it is appropriate to call Service and not Dao. You call Service requesting a service and Service responds using one or more DAOs, what Service needs is a Service problem and not yours.

The basic idea is to encapsulate problems and their resolution in classes, which in turn group the necessary functions. It is much easier to understand to be able to modify it within a few years when you no longer remember how you did this or when someone else wants to reuse your development.

Years ago I worked in C ... All the development was linear and there were only simple functions. For example, it was not possible to encapsulate all the functions related to clients so that they did not mix with suppliers or with those of stock management or billing.

Then the classes were invented and called C ++, believe me it was a breakthrough. PHP is only a C ++ adaptation. You call Service CheckRecords and use the data returned for whatever is necessary, and during development you can make a Service CheckRecords that returns a fixed array, for example, and while developing Service CheckRecords make a mini program that only prints the results returned by Service CheckRecords.

Marcus Nov 30 '19
Amazing thanks so much Patricia. Gonna follow your advice and use service. 
dave Leader
dave Nov 30 '19

+1 patricia

Remember this silly rhyme  "dao, thats where my queries go"   

The request path should go as follows:

plugin php file function  ->  service.php  -> dao file (if you need something) then back in reverse  from the dao to the service to the php file function.  

Technically you could put queries in the service file if you had no other choice but its not the standard practice.   I wish i had known that when i first started because im still working on getting some of my plugins updated to use the dao fully.  oops :(

The service files and dao files are there and have protections for a reason, to help protect what you put in them...  :)   

Never ever ever put a query in a plugin root php file, that is sloppy, lazy, and unprofessional.  

Also if you notice in my plugins i also change var names between functions/methods, its overkill but its a habbit of mine.   In other words the functions sends one var name, the handoff to the service file is under a different var name, and the dao is under a different var name.  


The Forum post is edited by dave Nov 30 '19
Marcus Nov 30 '19
Appreciate it very much guys.