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

Lets imagine my situation (it's fake, of course)... I have web-site that have 1000
Let's imagine the following situation: You have a simple php page with an html
Imagine situation like this: You have a working repo in bitbucket - you were
Imagine such situation that I have a function like this: Object f() { Object
Situation: Imagine that I have an item(page) located at 'sitecore/Content/Home/mypage' in my content tree.
imagine a situation where you have an application that needs to import data from
Imagine the following situation: I have two branches: DEV and MAIN. I'm working on
Imagine the following situation: struct Args { bool arg; }; void thing(Args arg) {
Probably a very basic beginner question. Imagine the following situation: I have an ASP.NET
I have a question about jQuery load best practice. Imagine the following situation: $(#div).on('click',

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.