Giter Site home page Giter Site logo

blazebundle's Introduction

Happyr BlazeBundle

Latest Version Build Status Code Coverage Quality Score Total Downloads

This bundle lets you configure dynamic routes. A piece of code explains the benefit:

// Generate the path /blog-post/{post_id}/comment/{comment_id}/edit
<a href="{{ path('edit_comment', {'comment_id':comment.id, 'post_id':comment.post.id}) }}">Click here</a>
<a href="{{ comment|blaze('edit') }}">Click here</a>

Installation

Step 1: Using Composer

$ composer require happyr/blaze-bundle

Step 2: Register the bundle

To register the bundles with your kernel:

// in AppKernel::registerBundles()
$bundles = array(
    // ...
    new Happyr\BlazeBundle\HappyrBlazeBundle(),
    // ...
);

Step 3: Configure the bundle

# app/config/config.yml

happyr_blaze:
  objects:
    Acme\DemoBundle\Entity\Foo:
      edit:
        route: 'foo_edit'
        parameters: {id:'getId'}
      show:
        route: 'foo_show'
        parameters: {id:'getId'}

    Acme\DemoBundle\Entity\Bar:
      show:
        route: 'bar_show'
        parameters: {id:'getId'}

    Acme\DemoBundle\Entity\Baz:
      anything:
        route: 'baz_show'
        parameters: {id:'getId', foo_id:'getFoo.getId'}

    #if you need support for routes where the objects have no relation:
    Acme\DemoBundle\Entity\FooBar:
      manage:
        route: 'foobar_manage'
        parameters: [{id: 'getId'}, {baz_id: 'getId', baz_name: 'getName'}, {bazbar_id: 'getSlug'}]
        complementaryObjects: ["Acme\DemoBundle\Entity\Baz", "Acme\DemoBundle\Entity\BazBar"]

Usage

Twig

{# foo is a Foo object #}
<a href="{{ foo|blaze('show') }}">Show Foo</a>

{# baz is a Baz object #}
<a href="{{ baz|blaze('anything') }}">Show Baz</a>

{# and the multiple objects .. #}
<a href="{{ [foobar,baz,bazbar]|blaze('manage') }}">Show Baz</a>

PHP

//AnyController.php
// ...
  public function SomeAction() {
    $blaze=$this->get('happyr.blaze');

    $showUrl = $blaze->getPath($foo, 'show');
    $manageUrl = $blaze->getPath($foobar, 'show', array($baz, $bazbar));

    // ...
  }

blazebundle's People

Contributors

nyholm avatar

Watchers

James Cloos avatar Logorn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.