Skip to content

BlueBearGaming/BaseBundle

Repository files navigation

BaseBundle

BaseBundle for Symfony2 projects. This bundle contains some shortcuts and code snippets to ease Symfony2 projects developpment.

Installation

php composer.phar require bluebear/basebundle

Getting started

BaseBundle offers some features to help you :

ControllerTrait

<?php
...
use BlueBear\BaseBundle\Behavior\ControllerTrait;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class MyController extends Controller {
    use ControllerTrait;
    
    ...

Your controller should have following methods (those methods are native in Symfony Controller):

public function createNotFoundException($message = 'Not Found', Exception $previous = null)
public function generateUrl($route, $parameters = array(), $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) 

ControllerTrait has following methods :

  • forward404Unless($condition, $message = '404 Not Found') : Forward current request to a 404 page if $condition is false
  • redirect($url, $status = 302) : Redirect to an url or a route (for route use "@my_route")
  • setMessage($message, $type = 'info', $parameters = []) : Add a flash message with a type and translations parameters
  • getConfig($key) : Return configuration key $key from container parameters
  • getRouting() : Return router service
  • getTranslator() : Return translator service
  • getSession() : Return session service
  • getEventDispatcher() : Return event dispatcher service
  • getEntityManager() : Return entity manager service
  • translate($string, $parameters = []) : Return entity manager service

ContainerTrait

ContainerTrait has following methods :

  • getContainer() : Return Container service
  • setContainer() : Set Container service

EntityManagerTrait

EntityManagerTrait has following methods :

  • getEntityManager() : Return EntityManager service
  • setEntityManager() : Set EntityManager service

ManagerTrait

...