Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Route with no action not passing named parameter

Hi all,

I have a route:


$config['routes'] = [
    '/organization/(:int)/' =>  [   'controller'=>  'organization',
                                    'action'     => 'index',
                                    'page'   => 1

that isn't being matched. Or rather it is being matched but the parameter isn't being passed to the action.

My action looks like this:

    public function indexAction($page = 4){
        echo $page;

For a URL like .../organization/2/, $page should have a value of 2, but instead its 4. If I use:


it shows NULL. What do I have to change to get the $page properly passed?

edited Sep '15

You can print_r($di["router"]->getMatchedRoute()) to see what route is being matched

That gives me what I'd expect - the default route:

Phalcon\Mvc\Router\Route Object
    [_pattern:protected] => #^/([\w0-9\_\-]+)/([\w0-9\.\_]+)(/.*)*$#u
    [_compiledPattern:protected] => #^/([\w0-9\_\-]+)/([\w0-9\.\_]+)(/.*)*$#u
    [_paths:protected] => Array
            [controller] => 1
            [action] => 2
            [params] => 3

    [_methods:protected] => 
    [_hostname:protected] => 
    [_converters:protected] => 
    [_id:protected] => 1
    [_name:protected] => 
    [_beforeMatch:protected] => 
    [_group:protected] => 


Shouldn't :int be outside brackets?

Shouldn't :int be outside brackets?

Yep - that was it! I figured it was something simple like that. Thanks.