使用 urlManager 在 url yii2 中隐藏 id [英] hide a id in url yii2 using urlManager

查看:31
本文介绍了使用 urlManager 在 url yii2 中隐藏 id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>'

我在 url manager 中写了这个规则,以便它在更新操作期间隐藏 id 我希望 url 应该是/id 应该被隐藏.但没有运气.例如:我有这个网址 mysite.com/controller/update/1 我希望网址是 mysite.com/controller/update

I have written this rule in url manager so that it hide id during update action i want the url should be / the id should be hidden. But no luck. eg: I have this url mysite.com/controller/update/1 i want the url to be mysite.com/controller/update

推荐答案

你试图实现的目标是不可能和无用的.

What you are trying to achieve is impossible and useless.

从逻辑上考虑.在这种情况下,Action 根本不知道应该加载和更新哪个模型.

Think about it logically. Action in this case simply won't know exactly what model should be loaded and updated.

我只看到一种可能的用例.

I see only one possible use case of that.

当你加载页面 post/update 时,然后从列表中选择 post 来更新并使用 AJAX 加载它.

When you load page post/update, then select post from list to update and load it with AJAX.

在这种情况下,只需从操作参数中删除 id,您无需为此编写额外的 url 规则.

In this case just remove id from action parameters, you don't need to write additional url rules for that.

这篇关于使用 urlManager 在 url yii2 中隐藏 id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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