What is the structure of a (Data Access) Service Class
- by jiewmeng
I learnt that I should be using service classes to persist entities into the database instead of putting such logic in models/controllers. I currently made my service class something like
class Application_DAO_User {
protected $user;
public function __construct(User $user) {
$this->user = $user
}
public function edit($name, ...) {
$this->user->name = $name;
...
$this->em->flush();
}
}
I wonder if this should be the structure of a service class? where a service object represents a entity/model? Or maybe I should pass a User object everytime I want to do a edit like
public static function edit($user, $name) {
$user->name = $name;
$this->em->flush();
}
I am using Doctrine 2 & Zend Framework, but it shouldn't matter