承接 popov/zfc-block 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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 Factory for this block;
  • use ReflectionFactory, this will be convenient if project is under development. Register factory in your config/autoload/dependencies.global.php
    return [
        // ...
        '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 ReflactionFactory on production, create real Factory for 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.

  • default key sets general configuration for Block
  • also configuration can be set per resource/action, where resource in most cases is controller or module taken 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 popov/zfc-block 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 167
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-05-25