I am a bit confused about how to follow insert and update instructions using MVC. Is it possible to create an instance of an object in your controller and transfer it to the service in order to save it or transfer data to the service and process everything else there?
Embed
In my controller , something like:
$userservice->insert("myname","mypassword");
In my UserService :
function insert($username,$password){ $user = ORM::for_table('user')->create(); $user->username= $username; $user->password= $password; $user->save(); }
Update
In my controller , something like:
$userservice->update("myname","mypassword",1);
In my UserService :
function insert($username,$password,$id){ $user = ORM::for_table('user')->find($id); $user->username= $username; $user->password= $password; $user->save(); }
Is this a good practice? Because I see many such answers, where, for example, the user is created in the controller and transferred to the repository to save it: Is the correct repository template template in PHP? But I do not like the idea of ββcreating a user in the controller ...
php model-view-controller
randomizer
source share