alexandresalome/web-bundle

This package is abandoned and no longer maintained. The author suggests using the symfony/framework-bundle package instead.

A bundle to make awesome web applications

v0.1.2 2014-01-31 21:24 UTC

This package is auto-updated.

Last update: 2019-06-27 09:23:44 UTC


README

I recommend you to pick snippets in the code, but not to use it actually (very unstable).

Installation

Add alexandresalome/web-bundle to your composer.json:

{
    "require": {
        "alexandresalome/web-bundle": "dev-master"
    }
}

Updates your dependencies and add it to your AppKernel:

public function registerBundles()
{
    return array(
        // ...

        new Alex\WebBundle\AlexWebBundle()
    )
}

Base controller

Controller from this bundle provides a bunch of useful methods.

Take a look at the class for an exhaustive feature list.

Data Fixtures

namespace Acme\DemoBundle\DataFixtures\ORM;

use Alex\WebBundle\DataFixtures\ORMFixture;
use Doctrine\Common\Persistence\ObjectManager;

class UserData extends ORMFixture
{
    public function load(ObjectManager $manager)
    {
        // access a container service
        $this->get('security.encoder_factory');
    }
}

Form templating

Twitter Bootstrap 3.0 templating is available in this bundle for forms. In Twig configuration, add form templating:

twig:
    form:
        resources: [ "AlexWebBundle::form_bootstrap3_layout.html.twig" ]

Locale listener

If you want to allow user to choose locale in a given set, you can turn on the locale listener by appending in your config.yml file:

alex_web:
    locale_listener: [ fr_FR, en_US, pt_PT ]

This configuration will constraint the user locale on one of those. Default behavior is to store this locale in session. If you don't want to use session but still want to use the listener:

alex_web:
    locale_listener:
        enabled: true
        locales: [fr_FR, en_US]
        session_key: null # disable persistence in session

Twig extension

|format_interval

Example:

Duration: {{ job.finishedAt.diff(jobStartedAt) }} {# should be job.duration #}

This method will transform DateInterval object to a string representation.

Pagination template

If you are using my pagination library, you might appreciate the template AlexWebBundle::pagination.html.twig. To use it:

{% embed "AlexWebBundle::pagination.html.twig" %}
    {% block colspan '3' %}
    {% block head %}
        <th>Username</th>
        <th>Fullname</th>
        <th>Actions</th>
    {% endblock %}
    {% block body %}
        {% for user in pager %}
            <tr>
                {# ... #}
            </tr>
        {% else %}
            <tr><td colspan="{{ block('colspan') }}"><em>no user</em></td></tr>
        {% endfor %}
    {% endblock %}
{% endembed %}

Form extra widgets

Form sections

Structure your form with sections. Sections will group fields with a legend above, so that your form is more structured:

$builder
    ->add($builder->create('informations' 'form_section')
        ->add('firstname', 'text')
        ->add('lastname', 'text')
    )
    ->add($builder->create('contacts', 'form_section')
        ->add('main', 'contact')
    )

Form tabs

Here is an example of a form with tabs:

$builder = $this->get('form.factory')->createBuilder('form_tabs');

$builder
    ->add($builder->create('informations', 'form_tab')
        ->add('firstname', 'text')
        ->add('lastname', 'text')
    )
    ->add($builder->create('contacts', 'form_tab')
        ->add('main', 'contact')
    )
;