Yii2 URL管理器不解析带有get参数的URL [英] Yii2 url manager don't parse urls with get parameter

查看:229
本文介绍了Yii2 URL管理器不解析带有get参数的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个名为catalog的模块,目前在默认控制器中有两个动作:

I've created a module named catalogue with, for the moment, two actions in the default controller:

  1. actionIndex
  2. actionLineProducts

在索引视图中,我有一些链接可以运行产品的操作,网址是以下结果:

in the index view I have some link which run the line-product's action, the url was the result of:

Url::to(['line-products', 'line' => $line->name])

我的目标是获得一个类似的链接

my goal is to obtain a link like

目录/{行名}

catalogue/{line-name}

其中line-name是我发送给操作LineProducts的参数. 我的urlManager配置为:

where line-name is the parameter I send to action LineProducts. My urlManager configurations are:

'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
      '<moduls:catalogue>/<controller:default>/<action:line-products>/<line:*>' => '<module>/<line>',
      '<controller:\w+>/<id:\d+>' => '<controller>/view/',
      '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
      '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
 ],

.htaccess配置:

.htaccess configurations:

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

谁能向我解释为什么我的URL总是像这样:

Can anyone explain me why my URL is always like:

http://my-site.dev/catalogue/default/line -products?line = {行名}

推荐答案

您交换了配置.关键是从浏览器传递的网址格式.该值是路线.由于您使用的是特定的模块,控制器和操作,因此您可以直接将其传递进来:

You swapped the configuration. The key is the pattern of the url as passed from the browser. The value is the route. Since you are using a specific module, controller and action you can pass those in directly:

'rules' => [
    'catalogue/<line>' => 'catalogue/default/line-products'
    ...
]

您可以阅读路由和网址创建"页面,请参见Yii2指南.

You can read the Routing and Url Creation page in the Yii2 guide for more information.

这篇关于Yii2 URL管理器不解析带有get参数的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆