第一个问题:我已经删除了index.php,但我/web也想删除.这是我的.htaccess
RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php
Run Code Online (Sandbox Code Playgroud)
这是 config/web.php
'urlManager' => [
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
],
Run Code Online (Sandbox Code Playgroud)
它工作正常,但它仍在使用/web.可以删除/web吗?
第二个问题:
我无法使用干净的网址,我的路线设置带参数的路线 Url::toRoute(['transaction/getrequestdetail/', 'id' => 1 …
我已经设置了Yii 2基本应用程序,并在config/web.php我使用下:
urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
]
Run Code Online (Sandbox Code Playgroud)
在components.
但是当我尝试运行我的应用程序时,我收到以下错误:
无效调用 - yii\base\InvalidCallException设置只读属性:yii\web\Application :: urlManager>
相同的urlManager代码在高级应用程序中工作正常.有什么想法吗?
好的,我正在将应用程序从yii 1.1转换为yii 2,不幸的是,我无法弄清楚如何在URL路由中使用可选参数。即使当我在配置中的urlmanager中设置默认值时,如果没有第一个参数,我也无法声明第二个参数,否则最终会出现404错误。
有没有办法复制可选的url参数规则,例如
array( '<controller:\w+>/<action:\w+>?(/<status>)?',
'pattern' => '<controller>/<action>'
),
Run Code Online (Sandbox Code Playgroud)
在yii 2中?
我有这样的网址
HTTP://本地主机/ yii2 /类别/我的定制字符串参数
我需要获取文本my-custom-string-parameter
我设置了这样的规则
'urlManager' => [
'class' => 'yii\web\UrlManager',
'showScriptName' => false,
'enablePrettyUrl' => true,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'category/<url:>' => 'category/view',
),
],
Run Code Online (Sandbox Code Playgroud)
这总是给我404错误.我该怎么办?
我有一个全局搜索表单,提交给控制器的搜索操作:
<?=Html::beginForm(['/feqh/search'], 'get', ['class' => 'navbar-form navbar-left', 'role' => 'search', 'id' => 'searchForm']);?>
<div class="form-group has-feedback Right">
<input id="q" type="text" class="form-control" placeholder="<?=yii::t('app','Search');?>" name="q" value="<?= Html::encode(\Yii::$app->getRequest()->getQueryParam('q',""));?>" />
<i class="form-control-feedback glyphicon glyphicon-search"></i>
</div>
<button type="submit" class="btn btn-default"><?=yii::t('app','Submit');?> <i class="glyphicon glyphicon-ok"></i></button>
</form>
Run Code Online (Sandbox Code Playgroud)
我决定为搜索规则制作漂亮的 URL,如下所示:
'search/<q:\w+>' => 'feqh/search',
Run Code Online (Sandbox Code Playgroud)
但是,提交表单总是会生成以下 URL:
example.com/feqh/search?q=anySearchString
但是,example.com/search/anySearchString可以访问。这里是使用表单提交的问题。
我尝试更改表单操作 URL:
<?=Html::beginForm(['feqh/search']即删除初始/但它没有任何区别。
顺便说一下,以下规则也有效:
'search' => 'feqh/search',它使example.com/search?q=anySearchString. However, the applying of this rule preventexample.com/search/anySearchString`
我正在使用高级项目应用程序,并尝试在 Yii2 中添加 URL 规则来处理带有破折号的自定义 URL。
我想要做的是将 URL 更改为
到
我有以下配置,当 URL 参数没有破折号时(exampleposttitle),该配置可以正常工作。
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
// ...
'<url:\w+>' => 'post/details',
],
],
Run Code Online (Sandbox Code Playgroud)