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

  • SEARCH
  • Home
  • 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 4572548
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:39:41+00:00 2026-05-21T19:39:41+00:00

Ive been working on a project with ZendFramework and Doctrine2 and have noticed an

  • 0

Ive been working on a project with ZendFramework and Doctrine2 and have noticed an issue with my action controllers not being very ‘DRY’. Given the following example, which is pretty much identical throughout all of my controllers what would be the best approach to factor out the repetition. I think that a baseController would be by far the easiest, but it seems that extending Zend_Controller_Action is frowned upon. The other two options that I am leaning toward is to create an action helper or controller plugin(but controller plugins these are still a fuzzy concept to me).
So my question is, what would be the best way to do this? and why?

class Job_JobController extends Zend_Controller_Action
{

   protected $_service;

   public function init()
   {
        $ajaxContext = $this->_helper->getHelper('AjaxContext');
        $ajaxContext->addActionContext('create', 'html')
                    ->addActionContext('update', 'html')
                    ->addActionContext('view', 'html')
                    ->addActionContext('delete', 'html')
                    ->addActionContext('message', 'html')
                    ->initContext();
        $this->_service = $this->_helper->service('job');
    }

    public function indexAction()
    {
         $this->_forward('list');
    }

    public function listAction()
    {
        $grid = $this->_service->getGrid();
        $this->view->list = $grid->render();      
    }

    public function createAction()
    {
        $request = $this->getRequest();
        $formMediator = $this->_service->getFormMediator();

        if ($request->isPost() && $formMediator->isValid($request->getPost()))
        {
            $this->_service->saveEntity($formMediator->transfer());
            $this->_helper->flashMessenger->addMessage(array('statusCode' => 'Create::Success'));
            $this->_forward('message');
        }

        $this->view->entity = $formMediator->getForm();       
    }

    public function updateAction()
    {
        $request = $this->getRequest();
        $formMediator = $this->_service->getFormMediator();
        $entity = $this->_service->findEntity($request->getParam('id'));

        if ($request->isPost() && $formMediator->isValid($request->getPost()))
        {
            $this->_service->saveEntity($formMediator->transfer($entity));
            $this->_helper->flashMessenger->addMessage(array('statusCode' => 'Update::Success'));
            $this->_forward('message');
        } 
        else
        {
            $formMediator->populate($entity);
        }

        $this->view->entity = $formMediator->getForm();
    }


    public function viewAction()
    {
        $request = $this->getRequest();
        $this->view->entity = $this->_service->getEntity($request->getParam('id'));
    }

    public function deleteAction()
    {
        $request = $this->getRequest();
        $id = $request->getParam('id');

        if ($this->getRequest()->isPost())
        {
            $this->_service->delete($request->getParam('id'));
            $this->_helper->flashMessenger->addMessage(array('statusCode' => 'Delete::Success'));
            $this->_forward('message'); 
         }

         $this->view->deleteId = $id;
    }

    public function messageAction()
    {
         $messages = array_merge((array)$this->_helper->flashMessenger->getMessages(), 
                     (array)$this->_helper->flashMessenger->getCurrentMessages());
         $this->view->messages = $messages;
    }

}
  • 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-21T19:39:42+00:00Added an answer on May 21, 2026 at 7:39 pm

    Not a real answer, but I think the both ways (extending Zend_Controller_Action, or Action-Helper) are the solutions you are looking for. I dont see any reason, why an abstract controller is somewhat … ugly(?), too. Its the way OOP works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working on a project in Delphi 7 where I wanted to have
I have a project i've been working on that requires me to retrieve the
I've been working on a project which uses SPNEGO to have Single Sign On
I've been working on a project where I have been using LinqToSQL that involved
I've been working on a project that requires draft/live versions of content and have
I'm trying to get a dylib working in my OSX project. Ive been reading
I've been working on a project at work and have come to the realization
So in the project ive been working on i use the youtube API to
Currently moving a project Ive been working on to a dev server but for
so ive been working on a small nodejs project and some of my user

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.