popov/zfc-block
Composer 安装命令:
composer require popov/zfc-block
包简介
Create separatly custom template bock with html, css, js etc.
README 文档
README
Create separately custom template bock with html, css, js etc.
Usage
For Expressive: register ZfcBlock module in config/config.php with Popov\ZfcBlock\ConfigProvider::class.
For MVC: register with Popov\ZfcBlock in your configuration.
Create new Block class in your module with name LoginBlock
// src/Your/Module/src/Block/LoginBlock.php namespace Stagem\Visitor\Block; use Popov\ZfcBlock\Block\Core; use Popov\ZfcUser\Form\LoginForm; class LoginBlock extends Core { /** * @var LoginForm */ protected $loginForm; public function __construct(LoginForm $loginForm) { $this->loginForm = $loginForm; } public function getLoginForm() { return $this->loginForm; } }
This class must extend Popov\ZfcBlock\Block\Core for allow usage basic functionality such as translate, check permission
and other auxiliary opportunities.
Next step you can:
- create
Factoryfor this block; - use
ReflectionFactory, this will be convenient if project is under development. Register factory in yourconfig/autoload/dependencies.global.phpreturn [ // ... 'block_plugins' => [ 'abstract_factories' => [ Zend\ServiceManager\AbstractFactory\ReflectionBasedAbstractFactory::class ], ] ];
If you decide use ReflectionFactory then minimum bare you need add alias for your block to configuration
// src/Stagem/Visitor/config/module.config.php return [ // ... 'block_plugins' => [ 'aliases' => [ 'VisitorLogin' => \Your\Module\Block\LoginBlock::class, ], ], 'block_plugin_config' => [ 'default' => [ \Your\Module\Block\LoginBlock::class => [ 'template' => 'visitor::login' ], ], ], ];
Be aware. Don't use
ReflactionFactoryon production, create realFactoryfor your block class.
After that your can call your block in any template with
<div>
<?= $this->block()->render('VisitorLogin') ?>
</div>
Or the same example with advanced usage
<div>
<?php $loginBlock = $this->block('VisitorLogin'); ?>
<?= $this->block()->render($loginBlock) ?>
</div>
Advanced usage can be useful for set additional parameters.
For example, block template can have next view
// src/Your/Module/view/visitor/login.phtml <?php $form = $block->getLoginForm(); $form->setAttribute('action', $this->url('default', [ 'controller' => 'visitor', 'action' => 'login', ])); $form->prepare(); ?> <?= $this->form()->openTag($form) ?> <div class="modal-content"> <div class="right-side"> <div class="form-group"> <label for="user"><?= $form->get('email')->getLabel() ?>:</label> <?= $this->formElement($form->get('email')) ?> </div> <div class="form-group"> <label for="password"><?= $form->get('password')->getLabel() ?>:</label> <?= $this->formRow($form->get('password')) ?> </div> </div> </div> <?= $this->form()->closeTag() ?>
Configuration
block_plugin_config in config file is used for set some specific configuration for Block.
All config parameters will be set with setter.
defaultkey sets general configuration forBlock- also configuration can be set per
resource/action, where resource in most cases iscontrollerormoduletaken from URL.
return [ // ... 'block_plugins' => [ 'aliases' => [ 'VisitorLogin' => \Your\Module\Block\LoginBlock::class, ], ], 'block_plugin_config' => [ 'visitor/login' => [ \Your\Module\Block\LoginBlock::class => [ 'template' => 'visitor::login' ], ], ], ];
If you need some complex parameters in your Block use Factory for this purpose.
Types
- list (roster)
In action:
public function process(\Psr\Http\Message\ServerRequestInterface $request) { $viewModel = (new ViewModel())->setTemplate('block::list') ->addChild($viewModelOne, 'one') ->addChild($viewModelTwo, 'two') ->addChild($viewModelThree, 'three'); return $viewModel; }
All your blocks will be rendered automatically one by one.
popov/zfc-block 适用场景与选型建议
popov/zfc-block 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 167 次下载、GitHub Stars 达 3, 最近一次更新时间为 2018 年 05 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 popov/zfc-block 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 popov/zfc-block 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 167
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-05-25