chris13/front-render-bundle

通过 Symfony 应用程序渲染前端应用程序。

1.4.0 2016-02-29 14:58 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:03:56 UTC


README

SensioLabsInsight Scrutinizer Code Quality Build Status Dependency Status

Front Render Bundle

通过 Symfony 2 应用程序渲染前端应用程序(AngularJs, BackboneJs...)

安装

步骤 1:下载 Bundle

打开命令行,进入您的项目目录,然后执行以下命令以下载此 Bundle 的最新稳定版本

$ composer require chris13/front-render-bundle "~1"

此命令需要您全局安装了 Composer,如 Composer 文档的安装章节所述。

步骤 2:启用 Bundle

然后,通过将其添加到项目 app/AppKernel.php 文件中注册的 Bundle 列表中来启用 Bundle

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Chris\Bundle\FrontRenderBundle\FrontRenderBundle(),
        );

        // ...
    }

    // ...
}

配置 Bundle

有两种不同的方法来配置前端应用程序的路径

-通过 config.yml 配置

-通过监听器配置

使用方法

渲染您的前端应用程序

<?php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class DefaultController extends Controller
{
    /**
     * @Route("/", name="homepage")
     */
    public function indexAction(Request $request)
    {
        $frontRender = $this->get('front_render_bundle.front_render');

        //Optional
        $frontRender
            ->setParameters(
            [
                'param' => 'param',
            ]
        );

        return new Response($frontRender->render());
    }
}

测试

在 Bundle 中运行单元测试

$ ./bin/phpunit --debug -c ./