tasmaniski / laminas-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 auto-updated.
Last update: 2024-09-09 19:19:11 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);