Yii 2静态页面 [英] Yii 2 static pages
问题描述
我无法显示静态页面.尝试按照文档此处的说明进行操作- http://stuff.cebe.cc/yii2-guide. pdf (第100页),但是当我启用prettyurl时,它不起作用.
I can't show static pages. Try do it as described in doc here - http://stuff.cebe.cc/yii2-guide.pdf (on page 100) but when I enable prettyurl, it doesn't work.
已在urlManager规则中添加:
Added in urlManager rules:
'urlManager' => array(
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => array(
'' => 'site/index',
'login' => 'site/login',
'contacts' => 'site/contact',
'<view:(break)>'=>'/site/page?&view=<view>',
),
),
然后在SiteController中添加:
then in SiteController added:
public function actions()
{
return [
...
'page' => [
'class'=>'yii\web\ViewAction',
],
];
}
然后创建views/site/pages/break.php
And then created views/site/pages/break.php
<h1>View static page Break</h1>
但是我得到一个错误: 未找到(#404) 无法解决该请求:site/page?& view = break
But I get an error: Not Found (#404) Unable to resolve the request: site/page?&view=break
如果我禁用prettyUrl:
If i disable prettyUrl:
//'enablePrettyUrl'=>true
然后我可以看到我的页面键入url:index.php?r = site/page& view = break
then i can see my page typing url: index.php?r=site/page&view=break
ViewAction有什么问题?
What's wrong with ViewAction?
推荐答案
我解决了我的问题.使用这样的行:
I solved my problem. use such lines:
'<view:(break)>' => 'site/page',
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
我强制使用页面的特定名称进行查看,在我的情况下为中断",因为无法使用此名称
I force use specific name of page for view, in my case it "break", because can't use this
'<view:[a-zA-Z0-9-]+>' => 'site/page',
(这会导致其他规则崩溃.)我认为可以更好地创建扩展UrlRule的自己的规则类",但是现在我不需要了.
(it causes crashing other rules.) I think it could better create "own rule class" extending UrlRule, but think that now I don't need this.
这篇关于Yii 2静态页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!