We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Route with no action not passing named parameter

Hi all,

I have a route:

<?php

$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;
        exit();

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

var_dump($this->dispatcher->getParam('page'));

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] => 
)


77.7k
Accepted
answer

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.