PHP code example of popov / zfc-block

1. Go to this page and download the library: Download popov/zfc-block library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

popov / zfc-block example snippets


// 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;
    }
}

    return [
        // ...
        'block_plugins' => [
            'abstract_factories' => [
                Zend\ServiceManager\AbstractFactory\ReflectionBasedAbstractFactory::class
            ],
        ]
    ];
    

// 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'
            ],
        ],
    ],
];

<div>    
    <?= $this->block()->render('VisitorLogin') 

<div> 
     $loginBlock = $this->block('VisitorLogin'); 

// src/Your/Module/view/visitor/login.phtml

$form = $block->getLoginForm();
$form->setAttribute('action', $this->url('default', [
    'controller' => 'visitor',
    'action' => 'login',
]));
$form->prepare();

return [
    // ...
    'block_plugins' => [
        'aliases' => [
            'VisitorLogin' => \Your\Module\Block\LoginBlock::class,
        ],
    ],
    'block_plugin_config' => [
        'visitor/login' => [
            \Your\Module\Block\LoginBlock::class => [
                'template' => 'visitor::login'
            ],
        ],
    ],
];

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;
}