andydune/rzn-view-component

ZF2 的视图组件模块。

v0.4.0 2014-02-05 10:42 UTC

This package is auto-updated.

Last update: 2024-09-12 19:47:59 UTC


README

A ZF2 模块,添加了视图助手 IncludeComponent。轻量级工具,用于将本地块插入页面,实现链:模型-模板-缓存。

插件包含三个元素:服务、视图和缓存。

基本使用

    <?= $this->includeComponent('bank-info', 	
                                'component/bank-info', 	
                                array('id' = $this->id), 
                                array()) ?>

有 4 个参数

  1. 注册的服务名称。
  2. 视图文件名称。它指向视图助手 "部分"。
  3. 要传递给服务的初始数据。
  4. 本地配置数组。

通过 Composer 安装

步骤

1. 添加到 composer。

    "require" : {
        "andydune/rzn-view-component": "dev-master"
    }

2. 如果需要更改基本配置,将配置文件(rzn-view-component.global.php)复制到您的应用程序自动加载目录。

3. 将模块添加到应用程序配置(/config/application.config.php)

   ...
   'modules' => array(
        'RznViewComponent',
   ),
   ...

配置

以下是基本配置

return array(
    'rznviewcomponent' => array(
        'cache_service' => 'cache_view_component',
        'cache_adapter' => array(
                                'name' => 'filesystem',
                                'options' => array(
                                    'ttl' => 3600,
                                    'dirLevel' => 2,
                                    'file_locking' => false,
                                    'cacheDir' => 'data/cache',
                                    'dirPermission' => 0755,
                                    'filePermission' => 0666,
                                ),
                            ),
        'cache_remove_item_key' => 'slay_component_cache', 
        'cache_allow'   => false, // check cache adapter options and set true to enable component cache
        'view_script_prefix' => '', // not used yet
        'use_result_object' => false
    )
); 

如果您想进行更改,请将 /module.config.php 复制到 /config/autoload/rzn-view-component.global.php 或将配置数组的一部分插入到您的应用程序配置中。

配置参数

1. cache_service

缓存服务的名称。模块有自己的描述性缓存服务 "cache_view_component"。您可以指定实现 Zend\Cache\Storage\StorageInterface 的您自己的服务。

2. cache_adapter

Zend 缓存工厂的配置数组。以下是默认值。

3. cache_remove_item_key

指定查询中的变量名称,正数值用于重置当前站点页面上的缓存组件。如果要禁用此功能,请指定空值。

示例: http://mymegasite.com/catalog/frogs.html?slay_component_cache=1

3. use_result_object

默认情况下,视图助手 includeComponent 返回要在网站页面上显示的 HTML。如果您需要助手返回额外的数据(块标题、结果标志),请设置 true。组件将返回哪些值需要在助手的第四个参数中定义。为此,请使用键 result_key_return

示例

    <?= $this->includeComponent('bank-info', 'component/bank-info', 	
                                array('id' = $this->id), 
                                array('result_key_return' => array('title'))) ?>

title 的值来自服务 bank-info 传递给视图的数据数组。结果对象实现数组接口并具有魔法函数 __toString

示例

请参阅 EXAMPLES.md

最后

插件可以使用。详细的描述将稍后提供。