tasmaniski / zend-params-helper

此包已被放弃且不再维护。作者建议使用https://github.com/tasmaniski/laminas-params-helper包。

视图辅助器,用于从 $_GET、$_POST 和视图中的路由读取数据

3.0.2 2020-04-09 15:47 UTC

This package is auto-updated.

Last update: 2020-11-09 11:00:22 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 Params Helper

视图辅助器将从 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);