yii 框架:url 路由 [英] yii framework: url routing
本文介绍了yii 框架:url 路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在学习 Yii 并遇到了 url 路由问题.我有一个控制器如下
I'm learning Yii and got into url routing problem. I have a controller as follows
class PageController extends Controller
{
public function actionIndex()
{
echo 'index';
}
public function actionGetPage($page = '')
{
echo $page;
}
在 config/main.php
and in config/main.php
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'page'=>'page/index',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
如何设置 url 规则,以便当我使用 http://localhost/page/About 时它应该可以工作并打印关于"
How can i set url rules so when i use http://localhost/page/About it should work and print "About"
推荐答案
实现方式:在你的路由配置中,你应该有类似的东西:
On way to do it: In your route configuration, you should have something like:
'page/<key>' => 'page/index',
并定义 actionIndex() 如下:
And define actionIndex() as follows:
public function actionIndex($key) {
echo $key;
...
注意 actionView... 所需的额外参数.这将等于 URL 中使用的.
Note the extra parameter required by actionView... . That will be equal to the used in the URL.
这篇关于yii 框架:url 路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文