What is the structure of a (Data Access) Service Class

Posted by jiewmeng on Stack Overflow See other posts from Stack Overflow or by jiewmeng
Published on 2010-12-25T01:49:49Z Indexed on 2010/12/25 1:54 UTC
Read the original article Hit count: 565

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

© Stack Overflow or respective owner

Related posts about php

Related posts about zend-framework