I have the following route setup.
$router->add('/schools', array(
'module' => 'schools',
'namespace'=>'MyNameSpace\Schools\Controllers\\',
'controller'=>'index',
'action' => 'index'
));
$router->add('/schools/:params',array(
'module' => 'schools',
'namespace'=>'MyNameSpace\Schools\Controllers\\',
'controller'=>'index',
'action' => 'index',
'params' => 1
));
$router->add('/schools/:action',array(
'module' => 'schools',
'namespace'=>'MyNameSpace\schools\Controllers\\',
'controller'=>'index',
'action'=>1
));
$router->add('/schools/:action/:params',array(
'module' => 'schools',
'namespace'=>'MyNameSpace\schools\Controllers\\',
'controller'=>'index',
'action'=>1,
'params'=>2
));
Problem:
1. https://www.example.com/schools/23
Works fine
2. https://www.example.com/schools/~school-name
Works as well
But,
3. https://www.example.com/schools/school-name
does not work
Where school-name
, ~school-name
and 23
in the above URLs are parameters to the default action (index)
of the controller.
I cannot print anything in the initialize
method of the controller. Tried putting try catch on main
method of index.php
as well, no errors.
I can't print anything when 3rd URL above is executed, I just get 1
printed on the browser, no other errors.
I then, printed matched route path in https://www.example.com/schools/~school-name
and it gave
Phalcon\Mvc\Router\Route Object
(
[_pattern:protected] => /schools/:params
[_compiledPattern:protected] => #^/schools(/.*)*$#
[_paths:protected] => Array
(
[module] => schools
[namespace] => MyNameSpace\Schools\Controllers\
[controller] => index
[action] => index
[params] => 1
)
[_methods:protected] =>
[_hostname:protected] =>
[_converters:protected] =>
[_id:protected] => 34
[_name:protected] =>
[_beforeMatch:protected] =>
[_group:protected] =>
)
Following route, the object is printed on https://www.example.com/schools/23
Phalcon\Mvc\Router\Route Object
(
[_pattern:protected] => /schools/:action/:params
[_compiledPattern:protected] => #^/schools/([a-zA-Z0-9\_\-]+)(/.*)*$#
[_paths:protected] => Array
(
[module] => schools
[namespace] => MyNameSpace\Schools\Controllers\
[controller] => index
[action] => 1
[params] => 2
)
[_methods:protected] =>
[_hostname:protected] =>
[_converters:protected] =>
[_id:protected] => 36
[_name:protected] =>
[_beforeMatch:protected] =>
[_group:protected] =>
)
Can anybody help me, what I m doing wrong here? Thanks