我有以下路线设置。
$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
));
问题:
1. http://www.example.com/schools/23
工作正常
2. http://www.example.com/schools/~23
也可以
但,
3. http://www.example.com/schools/school-name
不起作用, Whereschool-name
和~23
上面的 URL 是控制器23
默认操作的参数。(index)
我无法initialize
在控制器的方法中打印任何内容。尝试将 try catch 也放在main
方法上 index.php
,没有错误。
执行上面的第三个 URL 时,我无法打印任何内容,我只是1
在浏览器上打印,没有其他错误。然后,我打印了匹配的路由路径http://www.example.com/schools/~23
,它给出了
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] =>
)
跟随路线,对象被打印在http://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] =>
)
更新 令人惊讶的以下网址也有效
http://www.example.com/schools/~school-name
但不是http://www.example.com/schools/school-name
Phalcon\Mvc\Router\Route Object
(
[_pattern:protected] => /schools/:params
[_compiledPattern:protected] => #^/schools(/.*)*$#
[_paths:protected] => Array
(
[module] => agencies
[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] =>
)
谁能帮助我,我在这里做错了什么?谢谢