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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:15:21+00:00 2026-05-20T03:15:21+00:00

Imagine situation, when the url should looks like /catalog/sectionIdent?page=1 where page param is optional.

  • 0

Imagine situation, when the url should looks like

/catalog/sectionIdent?page=1

where page param is optional.

Of course, custom route should be defined. Consider the following code:

    $route = new Zend_Controller_Router_Route_Regex(
        'catalog/([-a-z]+)(?:\?page=([0-9]*))?',
        array('controller'=>'catalog','action'=>'list','page'=>''),
        array(1=>'section',2=>'page'),
        'catalog/%s?page=%d'
    );
    $router->addRoute('catalog-section-page',$route); 

But this route won’t be triggered with ‘?’ symbol in url.

Without ‘?’ (for example, by adding escaped ‘!’ symbol to pattern) everything works as it should.
Is there any way to achieve ‘?’ presence in custom defined regex route? Maybe I’m doing something wrong in pattern?

P.S.: Don’t offer to use ‘/’ instead of ‘?’, question is exactly about pattern restrictions in Zend_Controller_Router_Route_Regex implementation.

  • 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-20T03:15:22+00:00Added an answer on May 20, 2026 at 3:15 am

    The ZF routing classes operate on the REQUEST_URI with the query string stripped off, so you may have a hard time get this working in the way you are expecting. However, I believe GET parameters are put into the request object by default, so you shouldn’t need to cater for them in your routes. I’d suggest changing your route to remove the query string parts:

    $route = new Zend_Controller_Router_Route_Regex(
        'catalog/([-a-z]+)',
        array('controller'=>'catalog','action'=>'list'),
        array(1=>'section'),
        'catalog/%s'
    );
    $router->addRoute('catalog-section-page',$route); 
    

    You should still be able to access the params in your controller as if they had been populated by the routes:

    public function listAction()
    {
        echo $this->_getParam('page');
    }
    

    and you can use the same method to set a default:

    public function listAction()
    {
        $page = $this->_getParam('page', 1); // defaults to 1 if no page in URL
    }
    

    You just may need to sanitise them there (make sure they are numeric).

    Edit:

    Example of URL helper with this route:

    echo $this->url(array('section' => 'foo', 'page' => 2), 'catalog-section-page') 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine a situation, I have PC with two lan cards, one is connected to
Imagine you homebrew a custom gui framework that doesn't use windows handles (compact framework,
Imagine situation: I have view directory with tons of different views. all views have
Or any viable workaround. So, imagine a Master page that implements IFooMaster with a
Imagine we have a program trying to write to a particular file, but failing.
Imagine you want to animate some object on a WinForm. You setup a timer
Imagine an object you are working with has a collection of other objects associated
Imagine the scene, you're updating some legacy Sybase code and come across a cursor.
Imagine I have an function which goes through one million/billion strings and checks smth
Imagine this directory structure: app/ __init__.py sub1/ __init__.py mod1.py sub2/ __init__.py mod2.py I'm coding

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.