LexxpavlovPageBundle ================= This bundle helps you to manage your static pages in Symfony2 project. The bundle has a page entity with fields: * title - the title of page * content - html content. May use ckeditor for easy wysiwyg edit of content * slug - use as url of page. May be autogenerated based on title * published - enable or disable page * publishedAt, createdAt, updatedAt - Datetime fields, that contain actual information about page * meta: keywords and description - SEO info If you use SonataAdminBundle, this bundle automatically adds an entity to it. Installation ------------ ### Composer Download LexxpavlovPageBundle and its dependencies to the vendor directory. The bundle has a [StofDoctrineExtensionsBundle](https://github.com/stof/StofDoctrineExtensionsBundle) as required dependency and [IvoryCKEditorBundle](https://github.com/egeloen/IvoryCKEditorBundle) as optional dependency. You can use Composer for the automated process: ```bash $ php composer.phar require lexxpavlov/pagebundle ``` or manually add link to bundle into your `composer.json` and run `$ php composer.phar update`: ```json { "require" : { "lexxpavlov/pagebundle": "~1.0" }, } ``` Composer will install bundle to `vendor/lexxpavlov` directory. Bundle StofDoctrineExtensionsBundle will be installed automatically, if it didn't install earlier. ### Adding bundle to your application kernel ```php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(), new Lexxpavlov\PageBundle\LexxpavlovPageBundle(), // ... ); } ``` If you are already have `StofDoctrineExtensionsBundle` in the your `AppKernel`, you don't need to add its twice. Configuration ------------- First you must create your own page entity class. It's easy to make by extend base page from bundle. ```php **Note.** You may also execute `php app/console doctrine:schema:update --force` command, and Doctrine will create needed table for you. But I strongly recommend you to execute `--dump-sql` first and check SQL, which Doctrine will execute. Usage ----- If you use SonataAdminBundle, then you are already have admin tool for creating new pages. Otherwise you need to write your own creating tool, and here you may use predefined form: ```php $form = $this->createForm('lexxpavlov_page'); ``` There is the sample code for showing page, controller class and twig template. There are 3 different versions of action code, that doing the same - get page from database and show it in the twig template. Choose one or write your code. Controller: ```php {# src/App/YourBundle/Controller/DefaultController.php #} namespace App\YourBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use App\YourBundle\Entity\Page; class DefaultController extends Controller { /** * @Route("/page/{id}.html") * @Template() */ public function pageAction(Page $page) { } // or find by slug: /** * @Route("/page/{slug}") * @Template("AppYourBundle:Default:page.html.twig") */ public function slugAction(Page $page) { } // or find from repository /** * @Route("/page-find/{id}") * @Template("AppYourBundle:Default:page.html.twig") */ public function findAction($id) { $repository = $this->getDoctrine()->getRepository('AppYourBundle:Page'); if (is_numeric($id)) { $page = $repository->find($id); } else { $page = $repository->findOneBySlug($id); } return array('page' => $page); } } ``` And template: ```twig {# src/App/YourBundle/Resources/views/Default/page.html.twig #} {% extends '::layout.html.twig'%} {% block meta %} {% if page.metaKeywords is defined %} {% endif %} {% if page.metaDescription is defined %} {% endif %} {% endblock %} {% block body %}