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 7501853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:40:29+00:00 2026-05-29T20:40:29+00:00

I was reading this to understand zend’s MVC Request Lifecycle. But i can’t think

  • 0

I was reading this to understand zend’s MVC Request Lifecycle.
But i can’t think of any cases in zend where i would use a controller’s predispatch method , isn’t the init method enough for the code that i want executed before controller’s actions .

What should exactly should be in a controller’s predispatch and not init .

Can you give an example ?

  • 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-29T20:40:30+00:00Added an answer on May 29, 2026 at 8:40 pm

    See Zend_Controller_Action – Object Initialization and the following section Pre and Post Dispatch Hooks. They both go into some detail on the two, and the Action Controller itself.

    init() is more for setting up the controller object and doing initialization that will be available to all of your actions. Since init() runs prior to preDispatch(), anything you set up in init() will be available for preDispatch() to use. While it is possible to forward or redirect from init(), it is best practice to do it from preDispatch() because it runs prior to dispatching the controller action.

    From the manual:

    Note: Usage of init() vs. preDispatch() What is the difference between them (init and preDispatch), and what actions would you take
    in each?

    The init() method is primarily intended for extending the
    constructor. Typically, your constructor should simply set object
    state, and not perform much logic. This might include initializing
    resources used in the controller (such as models, configuration
    objects, etc.), or assigning values retrieved from the front
    controller, bootstrap, or a registry.

    The preDispatch() method can also be used to set object or
    environmental (e.g., view, action helper, etc.) state, but its primary
    purpose is to make decisions about whether or not the requested action
    should be dispatched. If not, you should then _forward() to
    another action, or throw an exception.

    Note: _forward() actually will not work correctly when executed from init(), which is a formalization of the intentions
    of the two methods.

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

Sidebar

Related Questions

I was reading this . I understand that application pool: Can seperate the process
I'm trying to understand how to use Type Converters after reading this answer to
after reading this question i wonder if someone can help me understand how to
I understand EOF and EOL but when I was reading this question (second part
I was reading this and unfortunately could not understand in depth why the compiler
After reading this - What does 'synchronized' mean? I was still unable to understand
I'm reading this C++ open source code and I came to a constructor but
Thanks for reading this. I would have thought it would be as simple as
I have been reading this article to understand the gcroot template. I understand the
From reading this question and answer , I understand that to clone a local

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.