Using this configuration for my base router. Calling he controller base uri, e.g. /test will resolve TestController::indexAction() properly in phalcon 1.2.6
Since I updated to phalcon 1.3. ( windows dll ), it tries to resolve TestController::2Action as it is the action key in the routes config.
Although I use Router groups with a subcontroller mvc setup, this behaviour is the same for using router directly and include the prefix in each path definition
$router = new Phalcon\Mvc\Router(false);
$router->removeExtraSlashes(true);
$router->setDefaultAction( 'index' );
$router->setDefaultController( 'index' );
$router->add( '/', array(
'controller' => 'index'
));
$hype = new \Phalcon\Mvc\Router\Group( array(
'controller' => 'index',
'action' => 'index'
) );
$hype->setPrefix( '/hype' );
$hype->add(
# all 3 working in 1.2.6 and phalcon 1.3 alpha
#"/(\w+)(?:/(\w+))?(/.*)*",
#"/:controller(?:/:action)?(?:/:params)?",
#"/([a-zA-Z0-9_-]+)(?:/([a-zA-Z0-9_]+))?(?:(/.*)*)?",
"/([a-zA-Z0-9_-]+)(?:/([a-zA-Z0-9_]+))?(?:(/.*)*)?",
array(
"namespace" => 'Hype\Controller',
"controller" => 1,
"action" => 2,
"params" => 3,
)
);
$hype->add( '', array(
"namespace" => 'Hype\Controller',
'controller' => 'index',
'action' => 'index'
));
$router->mount( $hype );
This simple test validates on phalcon 1.2.6 :
$testRoutes = array(
'/',
'/hype/',
'/hype/',
'/hype/controllerToken',
'/hype/controllerToken/',
'/hype/controllerToken/actionToken',
'/hype/controllerToken/actionToken/',
);
/** @var \Phalcon\Mvc\Router $router */
$router = $di->get("router");
foreach ($testRoutes as $testRoute) {
//Handle the route
$router->handle($testRoute);
echo 'Testing ', $testRoute, '<br>';
//Check if some route was matched
if ($router->wasMatched()) {
echo 'Controller: ', $router->getControllerName(), '<br>';
echo 'Action: ', $router->getActionName(), '<br>';
echo 'Namespace: ', $router->getNamespaceName(), '<br>';
} else {
echo 'The route `'.$testRoute.'` wasn\'t matched by any route<br>';
}
echo '<br>';
}
// Correct behaviour in phalcon 1.2.6 :
Testing /
Controller: index
Action: index
Namespace:
Testing /hype/
Controller: index
Action: index
Namespace: Hype\Controller
Testing /hype/
Controller: index
Action: index
Namespace: Hype\Controller
Testing /hype/controllerToken
Controller: controllerToken
Action: index
Namespace: Hype\Controller
Testing /hype/controllerToken/
Controller: controllerToken
Action: index
Namespace: Hype\Controller
Testing /hype/controllerToken/actionToken
Controller: controllerToken
Action: actionToken
Namespace: Hype\Controller
Testing /hype/controllerToken/actionToken/
Controller: controllerToken
Action: actionToken
Namespace: Hype\Controller
On phalcon 1.3 it doesn't resolve the action names. I get the numerical placeholders of the route config instead ( notice the Action: 2 output ) :
// Incorrect behaviour in phalcon 1.3 :
Testing /
Controller: index
Action: index
Namespace:
Testing /hype/
Controller: index
Action: index
Namespace: Hype\Controller
Testing /hype/
Controller: index
Action: index
Namespace: Hype\Controller
Testing /hype/controllerToken
Controller: controllerToken
Action: 2
Namespace: Hype\Controller
Testing /hype/controllerToken/
Controller: controllerToken
Action: 2
Namespace: Hype\Controller
Testing /hype/controllerToken/actionToken
Controller: controllerToken
Action: actionToken
Namespace: Hype\Controller
Testing /hype/controllerToken/actionToken/
Controller: controllerToken
Action: actionToken
Namespace: Hype\Controller
What's going on here? Should I submit this as an issue on github?