Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 940439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:57:27+00:00 2026-05-15T21:57:27+00:00

So we have a PHP+Zend Framework+Doctrine 1.2 application that has the following structure: Controller

  • 0

So we have a PHP+Zend Framework+Doctrine 1.2 application that has the following structure:

Controller -> Action -> Service -> Model

Not all models are interacted with through a service. Our current opinion is that a controller could use a model directly and a service could possibly use other services.

My question is: If you have a piece of business logic, what guidelines do you use to determine if the code that implements that logic should be in the Model, Controller, or Service layer? I am specifically interested in distinctions between the Controller and Service layer.

Here are the guidelines that our development team have come up with, but I am very interested in any feedback/input about them:

  1. Services and controllers contain
    logic for tying various components
    together to accomplish a task.
    This logic might not be in the
    model to avoid dependencies and make
    the model more reusable.
    This
    logic might also not be in the model
    because we think the model should
    avoid consuming things up the
    application stack to avoid
    unnecessary dependencies (ex: the
    model would not consume a service or
    controller).
  2. Use a service rather than a controller when the code may be used
    by multiple modules or controllers.
  3. A model should contain as much logic as possible but avoid
    referencing application-specific
    functionality. Usually a model
    contains at least validation logic.
  4. For any piece of functionality consider placing it in the model
    first. If there is a compelling
    reason not to, consider a service
    (also consider the overhead and
    purpose for maintain a new service).
    If a service is not desired and the
    code won’t be reused in this
    application use a controller.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:57:28+00:00Added an answer on May 15, 2026 at 9:57 pm

    In your context, I’d see models and controllers as both being parts of the business logic; the models defining “what” things are, the controllers defining “how” they are accessed.

    Services sit on top, potentially exposing the business logic to anything outside of the business logic layer. I agree with you that a service might encapsulate more than one specific component (or model to be more precise).

    Services and controllers contain logic
    for tying various components together
    to accomplish a task.

    Yes, I also agree with your statement on avoiding dependancies, etc. the model should not depend on anything excpet other closely related models (Common Closure Principle).

    In addition, if the logic is specific to a model – then that’s where it should go; if the logic is more generic it should be placed at the approriate level – possibly a controller or a common internal utility.

    Use a service rather than a controller
    when the code may be used by multiple
    modules or controllers.

    I agree. In terms of grainularity I would see services being at a higher level of abstraction – you’re more likely to expose a service to an external system than your “internal” controllers.

    A model should contain as much logic
    as possible but avoid referencing
    application-specific functionality.
    Usually a model contains at least
    validation logic.

    It should only contain logic that’s appropriate to be there, otherwise I agree. Validation – you could abtract that out; the model should definately contain the rules that validation uses but not necessarily the validation itself. I’ve seen both styles used and I don’t think there’s no wrong or right answer as long as you’re consistent.

    For any piece of functionality
    consider placing it in the model
    first. If there is a compelling reason
    not to, consider a service (also
    consider the overhead and purpose for
    maintain a new service). If a service
    is not desired and the code won’t be
    reused in this application use a
    controller.

    it depends what that “functinality” is, if it’s specific to a model then it probably belongs in the model; if it’s common to more than one model then it either belongs in a controller or a common utility class within the business logic.

    As I started writing all of this I wanted to put a stake in the ground around the definition of the terms you’ve used; I thought I’d include it anyway – so correct me if I’m wrong 🙂 And as you can see, I’m not clear on what you mean by an “action” in your context.

    • Model: (from Wikipedia – MVC) “The Model is used to manage information and notify observers when that information changes; it’s also a domain-specific representation of the data upon which the application operates.” To my mind this implies properties and the like – not methods.
    • Controller: (from Wikipedia – MVC) “Receives input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and viewport to perform actions based on that input.”
    • Service: There are many different opinions on what a service is, I assume in your context a service is: an externally facing callable point (within the context of the layers of your system) that provides a specific answer to a specific question. (Services being usually based around business concepts not technical ones.)
    • Action: I don’t know what you explicitly mean by this.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 534k
  • Answers 534k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Check out how Martin Erwig handled the same problem in… May 17, 2026 at 12:41 am
  • Editorial Team
    Editorial Team added an answer This is a Python bug. Passing the null string as… May 17, 2026 at 12:41 am
  • Editorial Team
    Editorial Team added an answer Right, apparently what I needed was the use of a… May 17, 2026 at 12:41 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a Zend_Framework application, which has a whole bunch of model classes. I
We have several php projects. The projects use the Zend Framework and we also
I would like to build a cms with php using zend framework. I have
Zend framework i have directory tree as following with robots.txt file, but when i
First some basic info: Ubuntu latest version Zend Framewrok 1.9.6 Doctrine 1.2.1 Php unit
i am on windows/apache/mysql/php setup. i have recently reinstalled PHP. but i found that
i use zend framework 1.10 and i have a script under scripts library. i
I'm integrating doctrine with Zend Framework. I've hit an error thrown from cli. It
I am going through the Zend Framework "quickstart" tutorial at the mo'. I have
I'm using Zend, a PHP library, to work with Amazon EC2. I have created

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.