Laminas (Zend Framework) Integration Guide

How to integrate Tplix with Laminas MVC and Mezzio using the service manager factory pattern.

Laminas · MVC / Mezzio

Tplix + Laminas

Register Tplix through the Laminas service manager factory in your module config.

composer require tplix/tplix
1

Register via Service Manager

module/Application/config/module.config.php
<?php
use Tplix\Tplix;

return [
    'service_manager' => [
        'factories' => [
            Tplix::class => function () {
                $tplix = Tplix::getInstance();
                $tplix->setTemplateDir(__DIR__ . '/../view/tplix');
                $tplix->setCompileDir(__DIR__ . '/../../../data/cache/tplix_c');
                return $tplix;
            },
        ],
    ],
];
2

Inject into a Controller

src/Controller/IndexController.php
<?php
namespace Application\Controller;

use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\Http\Response;
use Tplix\Tplix;

class IndexController extends AbstractActionController
{
    public function __construct(private Tplix $tplix) {}

    public function indexAction(): Response
    {
        $this->tplix->assign('title', 'Home');
        $response = $this->getResponse();
        $response->setContent($this->tplix->fetch('index.tpl'));
        return $response;
    }
}