sip/text-bundle

该包最新版本(dev-master)没有提供许可信息。

使用 SyliusResourceBundle 简单文本页面

安装: 26

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

dev-master 2013-05-18 20:44 UTC

This package is not auto-updated.

Last update: 2024-09-14 14:30:28 UTC


README

用于创建简单文本页面的 SonataAdmin 后端模块。

安装

  1. 命令将包添加到您的 composer.json 并下载包。
$ composer require "sip/text-bundle": "dev-master"
  1. 在内核中启用该包。
<?php

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        new SIP\TextBundle\SIPTextBundle(),
        new Genemu\Bundle\FormBundle\GenemuFormBundle(),
        // If you wish to use SonataAdmin
        new Sonata\BlockBundle\SonataBlockBundle(),
        new Sonata\jQueryBundle\SonatajQueryBundle(),
        new Sonata\AdminBundle\SonataAdminBundle(),

        // Other bundles...
    );
}

有关安装 SonataAdminBundle 的更多信息

  1. 创建您的实体
<?php
namespace MyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use SIP\TextBundle\Entity\Text as BaseText;

/**
 * @ORM\Entity
 * @ORM\Table(name="content_text")
 */
class Text extends BaseText
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }
}
  1. 更新数据库模式
$ php app/console doctrine:schema:update --force

这应该在开发环境中完成!我们建议使用 Doctrine 迁移来安全地更新您的模式。

  1. 导入路由配置
SIPTextBundle:
    resource: '@SIPTextBundle/Resources/config/routing.yml'
    prefix:   /
  1. 配置
# app/config/config.yml
sip_text:
    model: MyBundle\Entity\Text
    # All Default configuration:
    # controller: Sylius\Bundle\ResourceBundle\Controller\ResourceController
    # repository: Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository
    # admin: SIP\TextBundle\Admin\TextAdmin
  1. 模板

该包仅需要 show.html 模板。覆盖视图的最简单方法是将它放在这里 app/Resources/SIPTextBundle/views/Text/show.html.twig。

  1. 使用

为文本页面创建菜单

<?php

namespace MyBundle\Menu;

use Knp\Menu\FactoryInterface;
use Symfony\Component\DependencyInjection\ContainerAware;

class Builder extends ContainerAware
{
    public function mainMenu(FactoryInterface $factory)
    {
        $menu = $factory->createItem('root', array(
            'childrenAttributes' => array(
                'class' => 'nav'
            )
        ));

        $childOptions = array(
            'attributes'         => array('class' => 'dropdown'),
            'childrenAttributes' => array('class' => 'dropdown-menu'),
            'labelAttributes'    => array('class' => 'dropdown-toggle', 'data-toggle' => 'dropdown', 'href' => '#')
        );

        $child = $menu->addChild('Text pages', $childOptions);

        $textPages = $this->getTextRepository()->findBy(array('disabled' => 0));
        foreach ($textPages as $textPage) {
            $child->addChild($textPage->getTitle(), array(
                'route'           => 'sip_text_text_item',
                'routeParameters' => array(
                    'slug'  => $textPage->getSlug()
                ),
                'labelAttributes' => array('icon' => 'icon-chevron-right')
            ));
        }

        return $menu;
    }

    public function getTextRepository()
    {
        return $this->container->get('sip_text.repository.text');
    }
}

现在您有一个文本页面的菜单,您可以在模板中使用它。 有关渲染 knp 菜单的更多信息