sip / text-bundle
Simple text page using SyliusResourceBundle
Installs: 26
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- genemu/form-bundle: 2.1.*
- sonata-project/admin-bundle: master-dev
This package is not auto-updated.
Last update: 2025-01-18 16:18:01 UTC
README
Module for create simple text pages with SonataAdmin backend.
Installation
- command to add the bundle to your composer.json and download package.
$ composer require "sip/text-bundle": "dev-master"
- Enable the bundle inside the kernel.
<?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
- Creating your entity
<?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; } }
- Updating database schema
$ 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.
- Importing routing configuration
SIPTextBundle: resource: '@SIPTextBundle/Resources/config/routing.yml' prefix: /
- Configuration:
# 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
- 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.
- Usage
Create a menu for text pages
<?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'); } }
Now you have a menu of text pages and you can use it in your template. Read more about rendering knp menu