[英]What's difference between different ways to get GET parameter in Controller-Action in Zend framework 2?
I found several ways to get GET
parameters inside Controller > Action in Zend Framework 2 : 我找到了几种在Zend Framework 2中的Controller> Action中获取GET
参数的方法:
$this->params()->fromRoute('id');
$this->params('id');
$this->getRequest()->getQuery()->get('id');
Is there any difference among these ways? 这些方式有什么不同吗?
I guess, params('id')
may give values from GET
and POST
both. 我想, params('id')
可以给出GET
和POST
两者的值。 fromRoute and getQuery will give value from GET
only, but fromRoute
may give some advantages like sanitation or something? fromRoute和getQuery只能从GET
价值,但是fromRoute
可能会带来卫生等优点吗?
$this->params()->fromRoute('id');
This uses the params plugin and returns a single named route parameter. 这使用params插件并返回单个命名的路由参数。 This is used for parameters in segment routes (eg 'slug' from /blog/:slug
or 'year' from /archive/:year/:month/:day
). 这用于段路径中的参数(例如来自/blog/:slug
'slug'或来自/archive/:year/:month/:day
'year')。
$this->params('id');
This is just shorthand for $this->params()->fromRoute('id');
这只是$this->params()->fromRoute('id');
简写$this->params()->fromRoute('id');
. 。
$this->getRequest()->getQuery()->get('id');
This grabs a value from the query string. 这将从查询字符串中获取值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.