tasmaniski / zf2-params-helper
用于在视图中从 $_GET, $_POST 和路由读取数据的助手视图
3.0.2
2020-04-09 15:47 UTC
Requires
- php: >=5.6
- laminas/laminas-dependency-plugin: ^1.0
- laminas/laminas-mvc: ^3.0
This package is not auto-updated.
Last update: 2024-09-18 19:14:13 UTC
README
IMPORTANT NOTE: If you find this package useful, please click on a star button and let me know, so I will gladly continue with the updates.
Laminas MVC 参数助手
视图助手将读取 Laminas MVC 项目中的 $_GET, $_POST 和路由中的参数。
安装
将以下内容添加到您的 composer.json 文件中
{ "require": { "tasmaniski/laminas-params-helper": "^3.0" } }
运行 composer update 后
您需要注册新模块。在文件 config/application.config.php 中添加
'modules' => array(
'...',
'ParamsHelper'
),
使用
我们可以在任何视图文件(包括布局)中作为键名 params() 使用它。视图助手 params() 用于从 $_POST, $_GET 或路由中读取变量。
//will read all variables from $_POST $this->params()->fromPost(); //will read all variables from Routes $this->params()->fromRoute(); //will read all variables from $_GET $this->params()->fromQuery();
或者,您可以通过名称获取一个变量。第二个参数是可选的,如果助手找不到键,则使用默认值。
//will read var with name 'id' and if id is null it will return 1 as default $this->params()->fromRoute('id', 1);