0

在 Zend Expressive 中,布局是“默认”到“模板”文件夹中。

我想像这样将“admin”文件夹添加到“templates”文件夹中:

  • 模板
    • 行政
      • 应用程序
        • 管理页面.phtml
      • 错误
        • 404.phtml
        • 错误.phtml
      • 布局
        • 默认.phtml
    • 默认
      • 应用程序
        • 主页.phtml
      • 错误
        • 404.phtml
        • 错误.phtml
      • 布局
        • 默认.phtml

我已经尝试使用 Zend expressive 的教程来添加新布局,但对我来说没有成功......

class AdminPageHandler implements RequestHandlerInterface
{
    private $template;


    public function __construct(TemplateRendererInterface $template)
    {
        $this->template = $template;
    }

    public function handle(ServerRequestInterface $request) : ResponseInterface
    {

        $data = [
            'admin' => 'layout::admin',
            // or 'layout::admin',
            // or 'layout::alternative',
        ];
        $content = $this->template->render('pages::admin-page', $data);
        return new HtmlResponse($content);
    }
}

如何为我的管理仪表板添加新布局?

我想为我的管理仪表板添加新布局,因为 HTML 脚本与我的主应用程序不同。

4

1 回答 1

1

模板路径可以在 ConfigProvider 类 => __invoke 方法、'templates' => 'paths' 或 getTemplates() 方法中找到。在那里你应该添加一个新路径:

/**
     * Returns the templates configuration
     */
    public function getTemplates(): array
    {
        return [
            'paths' => [
                'app'    => [__DIR__ . '/../templates/app'],
                'error'  => [__DIR__ . '/../templates/error'],
                'layout' => [__DIR__ . '/../templates/layout'],
                'admin'  => [__DIR__ . '/../templates/admin'],
            ],
        ];
    }

那么你的处理程序应该看起来像这样

public function handle(ServerRequestInterface $request) : ResponseInterface
    {

        $data = [
            'admin' => 'layout::admin',
            // or 'layout::admin',
            // or 'layout::alternative',
        ];
        $content = $this->template->render('admin::app/admin-page', $data);
        return new HtmlResponse($content);
    }
于 2019-04-15T15:15:14.790 回答