2017 © Pedro Peláez
 

symfony-bundle form-bundle

Opifer Form Bundle

image

opifer/form-bundle

Opifer Form Bundle

  • Friday, January 29, 2016
  • by rvanlaarhoven
  • Repository
  • 6 Watchers
  • 0 Stars
  • 708 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 6 Versions
  • 9 % Grown

The README.md

Build Status, (*1)

Opifer FormBundle

Installation

Add OpiferForm to your composer.json:, (*2)

$ composer require opifer/form-bundle "~0.1"

Register the bundle in app/AppKernel.php:, (*3)

public function registerBundles()
{
    $bundles = array(
        // ...
        new Opifer\EavBundle\OpiferEavBundle(),
        new Opifer\FormBundle\OpiferFormBundle()
    );
}

Install the OpiferEavBundle according to its documentation., (*4)

Extend the Form & Post models;, (*5)

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Opifer\FormBundle\Model\Form as BaseForm;

/**
 * @ORM\Entity()
 * @ORM\Table(name="form")
 */
class Form extends BaseForm
{

}

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Opifer\EavBundle\Model\EntityInterface;
use Opifer\FormBundle\Model\Post as BasePost;

/**
 * @ORM\Entity()
 * @ORM\Table(name="post")
 */
class Post extends BasePost implements EntityInterface
{

}

Define these in the config along with your admin email:, (*6)

opifer_form:
    from_email: noreply@yourcompany.com
    form:
        class: AppBundle\Entity\Form
    post:
        class: AppBundle\Entity\Post

To be able to manage and use your forms, add some routes to your app/config/routing.yml:, (*7)

opifer_form:
    resource: "@OpiferFormBundle/Resources/config/routing.yml"

opifer_form_admin:
    resource: "@OpiferFormBundle/Resources/config/routing_admin.yml"
    prefix: /admin

Usage

Once you created your forms in your admin panel, you might want to display them on the frontend. To do this, you'd have to create a controller action that retrieves the form and displays it on the frontend, (*8)

namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class PageController extends Controller
{
    public function contactAction()
    {
        $form = $this->get('opifer.form.form_manager')->getRepository()->find(1);

        return $this->render('Page/contact.html.twig', array(
            'form' => $form
        ));
    }
}
{# app/Resources/views/Page/contact.html.twig #}

{% set form = create_form_view(form) %}
{{ form_start(form) }}
    {{ form_widget(form) }}
    <input type="submit" value="save">
{{ form_end(form) }}

The Versions