origammi/blocks-bundle

Symfony2 扩展包,用于向任何实体添加不同类型的区块。

安装: 683

依赖者: 0

建议者: 0

安全性: 0

星星: 2

关注者: 15

分支: 1

开放问题: 0

类型:symfony-bundle

dev-master / 1.0.x-dev 2015-08-18 09:05 UTC

This package is not auto-updated.

Last update: 2020-01-10 15:16:21 UTC


README

Build Status

使用方法

要求

  • PHP 5.4+

注册扩展包

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Origammi\Bundle\BlocksBundle\OrigammiBlocksBundle($this),
        new Infinite\FormBundle\InfiniteFormBundle,
        // ...
    );
}

准备实体

<?php

namespace AppBundle\Entity;

use Origammi\Bundle\BlocksBundle\Annotation as Origammi;
use Origammi\Bundle\BlocksBundle\Entity\BlockCollection;

class Post
{
    // ...
    /**
     * @var BlockCollection
     *
     * @ORM\ManyToOne(targetEntity="Origammi\Bundle\BlocksBundle\Entity\BlockCollection", cascade={"remove", "persist"})
     * @Origammi\BlockCollectionData(
     *  allowed={"lead", "text", "quote"},
     *  required={"lead"}
     * )
     */
    private $blocks;

    /**
     * @var BlockCollection
     *
     * @ORM\ManyToOne(targetEntity="Origammi\Bundle\BlocksBundle\Entity\BlockCollection", cascade={"remove", "persist"})
     * @Origammi\BlockCollectionData(
     *  allowed={"text"},
     *  required={"text"}
     * )
     */
    private $sidebarBlocks;
    
    // ...
    
    
    /**
     * @return BlockCollection
     */
    public function getBlocks()
    {
        return $this->blocks;
    }

    /**
     * @param BlockCollection $blocks
     *
     * @return $this
     */
    public function setBlocks(BlockCollection $blocks)
    {
        $this->blocks = $blocks;

        return $this;
    }

    /**
     * @return BlockCollection
     */
    public function getSidebarBlocks()
    {
        return $this->sidebarBlocks;
    }

    /**
     * @param BlockCollection $blocks
     *
     * @return $this
     */
    public function setSidebarBlocks(BlockCollection $blocks)
    {
        $this->sidebarBlocks = $blocks;

        return $this;
    }

}

创建表单

<?php

$form = $this
            ->createFormBuilder($post)
            ->add('blocks', 'origammi_blocks')
            ->add('sidebarBlocks', 'origammi_blocks')
            ->getForm();

资产(可选)

如果您正在使用 Admin LTE2,请确保在布局中加载资产。

<script type="text/javascript" src="{{ asset('bundles/origammiblocks/js/main.js') }}"></script>
'bundles/origammiblocks/css/admin-lte2.css'