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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:09:49+00:00 2026-06-14T09:09:49+00:00

I’m building my first Zend Framework application and I want to find out the

  • 0

I’m building my first Zend Framework application and I want to find out the best way to fetch user parameters from the URL.

I have some controllers which have index, add, edit and delete action methods. The index action can take a page parameter and the edit and delete actions can take an id parameter.

Examples
    http://example.com/somecontroller/index/page/1
    http://example.com/someController/edit/id/1
    http://example.com/otherController/delete/id/1

Until now I fetched these parameters in the action methods as so:

class somecontroller extends Zend_Controller_Action
{
    public function indexAction()
    {
        $page = $this->getRequest->getParam('page');
    }
}

However, a colleague told me of a more elegant solution using Zend_Controller_Router_Rewrite as follows:

$router = Zend_Controller_Front::getInstance()->getRouter();

$route = new Zend_Controller_Router_Route(
                        'somecontroller/index/:page',
                        array(
                            'controller' => 'somecontroller',
                            'action'    => 'index'
                        ),
                        array(
                            'page' => '\d+'
                        )
);

$router->addRoute($route);

This would mean that for every controller I would need to add at least three routes:

  • one for the “index” action with a :page parameter
  • one for the “edit” action with an :id parameter
  • one for the “delete” action with an :id parameter

See the code below as an example. These are the routes for only 3 basic action methods of one controller, imagine having 10 or more controllers… I can’t imagine this to be the best solution. The only benefit that i see is that the parameter keys are named and can therefore be omitted from the URL (somecontroller/index/page/1 becomes somecontroller/index/1)

// Route for somecontroller::indexAction()
$route = new Zend_Controller_Router_Route(
                        'somecontroller/index/:page',
                        array(
                            'controller' => 'somecontroller',
                            'action'     => 'index'
                        ),
                        array(
                            'page' => '\d+'
                        )
);

$router->addRoute($route);

// Route for somecontroller::editAction()
$route = new Zend_Controller_Router_Route(
                        'somecontroller/edit/:id',
                        array(
                            'controller' => 'somecontroller',
                            'action'     => 'edit'
                        ),
                        array(
                            'id' => '\d+'
                        )

$router->addRoute($route);

// Route for somecontroller::deleteAction()
$route = new Zend_Controller_Router_Route(
                        'somecontroller/delete/:id',
                        array(
                            'controller' => 'somecontroller',
                            'action'     => 'delete'
                        ),
                        array(
                            'id' => '\d+'
                        )

$router->addRoute($route);
  • 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-06-14T09:09:51+00:00Added an answer on June 14, 2026 at 9:09 am

    I tend to look at it this way:

    1. Determine processing requirements.

      What does each “action” need? An edit action and a delete action probably require an :id param. An add action and a list action probably do not. These controllers/actions then consume the params and do the processing.

      Note: You can write these comtrollers/actions without any reference to the urls that bring visitors there. The actions simply expect that their params will be delivered to them.

    2. Decide (!) what url’s you want.

      In general, I find the the (/:module/):controller/:action part of the url largely works fine (except for top-level relatively-static pages like /about, where I often put the actions on an IndexController (or a StaticController) and resent having to include the /index prefix in the url.

      So, to handle posts, you might want urls like:

      • /post – list all posts, probably with some paging
      • /post/:id – display a specific post
      • /post/:id/edit – edit a specific post
      • /post/:id/delete – delete a specific post
      • /post/add – add a post

      Alternatively, you might want:

      • /post/list – list all posts, probably with some paging
      • /post/display/:id – display a specific post
      • /post/edit/:id – edit a specific post
      • /post/delete/:id – delete a specific post
      • /post/add – add a post

      Or any other url scheme. The point is, you decide the url’s you want to expose.

    3. Create routes…

      …that map those urls to controllers/actions. [And make sure that whenever you render them, you use the url() view-helper with the route-name, so that a routing change requires no changes to your downstream code in your actions or views.

    Do you end up writing more routes this way? Yeah, I find that I do. But, for me, the benefit is that I get to decide on my urls. I’m not stuck with the Zend defaults.

    But, as with most things, YMMV.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm interested in microtypography issues on the web. I want a tool to fix:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I want to show the soap response to UIWebview.. my soap response is, <p><img

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.