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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:08:23+00:00 2026-06-08T04:08:23+00:00

I have a controller that can be invoked as modulename/xmlcoverage with index action and

  • 0

I have a controller that can be invoked as modulename/xmlcoverage with index action and some other actions, let say testAction().
The url to this controller is xml/coverage.

The default way is then that xml/coverage maps to my index action. And that xml/coverage/test maps to testAction. If I need an id for testAction, the url would be like xml/coverage/test/33 for instance.

However, for index action, it would need to be xml/coverage/index/33
Where I would like it to be xml/coverage/33.

This is my route

'xmlcoverage' => array(
        'type'    => 'segment',
        'options' => array(
                'route' => '/xml/coverage[/:action][/:id]',
                'constraints' => array(
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id'     => '[0-9]+',
                ),
                'defaults' => array(
                        'controller' => 'modulename/xmlcoverage',
                        'action'     => 'index',
                ),
        ),
),

When trying the url xml/coverage/33, I believe 33 should map to id, as it doesn’t match the regex of action and both are optional. And since it doesn’t match an action, the default (index) should be used.

Instead I get an error saying that the url cannot be matched by routing.
So for me, it acts as if the route was '/xml/coverage[/:action[/:id]]' because I for some reason have to specify action for it to recognize the id.

What am I doing wrong, and how can I get the urls to work as I’d like?
Thanks.

EDIT: Here is a problem.
Doing this in my view:

$this->url('xmlcoverage', array('action' => 'index', 'id' => $someid))

actually gives an URL on the form xml/coverage/1 which will crash!
Changing the route to /xml/coverage[/:action[/:id]] will at least make the url helper produce working urls..

  • 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-08T04:08:26+00:00Added an answer on June 8, 2026 at 4:08 am

    After talking and debugging with the nice ZF2 folks on IRC, we tracked down a bug in the routing.

    During the discussion I made a small example to my issue, which is here.
    As you can see from the var dump here, the action gets lost in the second case where it should default to “index”.

    But if anyone needs this functionality to work right now, here are ways that fix it:

    1. Instead of having the route to be /test[/:action][/:id] have it to be /test[/:action[/:id]], then the url helper will add /index/ and at least it works.
    2. Make a new route where you only listen for /test[/:id] in addition to the other one.
    3. In your controller, do public function notFoundAction() { $view = new ViewModel($this->indexAction()); //etc} Kinda hacky, but with this bug it will dispatch a not found action, which you can piggyback.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Rails controller action to test. In that action, a method User.can?
Let's say I have an async controller like that below ~ public class HomeController
In my controller I have model operations that can return empty results. I've setup
I have a controller that runs some calculation on data, and then I need
I have a controller decorated with an AuthorizeAttribute. The controller contains several actions that
I need to define some common piece of code that can be invoked from
I have a controller that looks like this: public class PageController : Controller {
I have a controller that contains a tableView that spawns another controller modally to
I have a controller that is called with AJAX (sends JSON data), so I
--Summary (shortened)-- I have a controller that loads a profile object from the corresponding

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.