2017 © Pedro Peláez
 

symfony-bundle text-bundle

Simple text page using SyliusResourceBundle

image

sip/text-bundle

Simple text page using SyliusResourceBundle

  • Saturday, May 18, 2013
  • by iljasuhinin
  • Repository
  • 1 Watchers
  • 0 Stars
  • 26 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Simple text page bundle

Module for create simple text pages with SonataAdmin backend., (*1)

Installation

1. command to add the bundle to your composer.json and download package.

``` bash $ composer require "sip/text-bundle": "dev-master", (*2)


2. Enable the bundle inside the kernel. --------------------------------------- ``` php <?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... ); }

Read more about installation SonataAdminBundle, (*3)

3. Creating your entity

``` php <?php namespace MyBundle\Entity;, (*4)

use Doctrine\ORM\Mapping as ORM; use SIP\TextBundle\Entity\Text as BaseText;, (*5)

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

/**
 * Get id
 *
 * @return integer
 */
public function getId()
{
    return $this->id;
}

}, (*7)


4. Updating database schema --------------------------- ``` bash $ php app/console doctrine:schema:update --force

This should be done only in dev environment! We recommend using Doctrine migrations, to safely update your schema., (*8)

5. Importing routing configuration

``` yml SIPTextBundle: resource: '@SIPTextBundle/Resources/config/routing.yml' prefix: /, (*9)


6. Configuration: ----------------- ``` yml # 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

7. Templates

The bundle requires only the show.html template. Easiest way to override the view is placing it here app/Resources/SIPTextBundle/views/Text/show.html.twig., (*10)

8. Usage

Create a menu for text pages, (*11)

``` php <?php, (*12)

namespace MyBundle\Menu;, (*13)

use Knp\Menu\FactoryInterface; use Symfony\Component\DependencyInjection\ContainerAware;, (*14)

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

    $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');
}

} ```, (*16)

Now you have a menu of text pages and you can use it in your template. Read more about rendering knp menu, (*17)

The Versions

18/05 2013

dev-master

9999999-dev

Simple text page using SyliusResourceBundle

  Sources   Download

The Requires

 

07/05 2013

0.1.1.x-dev

0.1.1.9999999-dev

Simple text page using SyliusResourceBundle

  Sources   Download

The Requires

 

17/04 2013

0.1.0.x-dev

0.1.0.9999999-dev

Simple text page using SyliusResourceBundle

  Sources   Download

The Requires