Create service class in PHP with Zend Framework

Description:

Communicate between modules in MCV architecture like PhP’s Zend Framework.

Solution:

Communication between modules, in MCV architecture should not be done directly by calling the model class, but accessing a service class assigned to the model.

A service class represents the mirror image of the original model class.

Name of class: class ModuleName_Service_ClassName

Parameters: private $_model;

Methods: protected function _getModel()

After this previous requirements the model methods are described, just with function name and return value.

Example:

class Customer_Service_Address {

        private $_model;

    protected function _getModel() {
        $this->_model = new Customer_Model_Address();
        return $this->_model;
    }

    public function updatePostcode($postcode) {
        return $this->_getModel()->updatePostcode($postcode);
    }

}

Advertisements

About admin

Just another php developer trying to give something back to the community.
This entry was posted in Best practices, PhP and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s