Giter VIP home page Giter VIP logo

chcmsexposeroutingplugin's Introduction

chCmsExposeRoutingPlugin: expose your symfony routes to javascript

Goal

chCmsExposeRoutingPlugin is a symfony 1.(3|4) plugin used to expose routing definition to the client side.

if you use symfony2, have a look to FriendsOfSymfony/FOSJsRoutingBundle

Requirement

You need jquery to use this plugin. jQuery is not bundeled with this plugin, you have to include it yourself.

How does it work ?

Enable

First, enable the plugin in your project configuration:

<?php
// config/ProjectConfiguration.class.php

public function setup()
{
  $this->enablePlugins(array('chCmsExposeRoutingPlugin'));
}

Then enable chCmsExposeRouting in your application:

# app/{your_app}/config/settins.yml

    enabled_modules:
      - chCmsExposeRouting

And finaly publish assets

$ symfony plugin:publish-assets

you're done !

More conf

You can disable the script auto inclusion by adding the following in your routing.yml

app:
  ch_cms_expose_routing:
    register_scripts: false # you will have to register scripts manually

You can disable the route auto declaration by adding the following in your routing.yml

app:
  ch_cms_expose_routing:
    register_routes: false # you will have to register script route manually

and the register your route this way:

my_custom_route_name:
  url: /my/url/route.js
  params: { module: chCmsExposeRouting, action: index }

register your exposed routes

make a route exposable

the only thing you need to do is to add an app_expose option:

// app/{your_app}/config/routing.yml

# this route will be exposed if auto_discover is true
my_route_to_expose:
  url:  /foo/:id/bar
  params: { action: foo, module: bar }
  options:
    app_expose: true

# this route will NEVER be exposed
my_secret_route:
  url:  /foo/:id/bar/1
  params: { action: foo, module: bar }
  options:
    app_expose: false

# this route will be exposed if forced, but not autodetected
a_default route:
  url:  /foo/:id/bar/2
  params: { action: foo, module: bar }

force a route exposition

in your application config ( app.yml ), add the following:

app:
  ch_cms_expose_routing:
    routes_to_expose:
      - my_first_route_to_expose
      - another_route

expose all exposable routes

if you want to expose all routes with app_expose option to true, just add the following to your application config ( app.yml ):

app:
  ch_cms_expose_routing:
    auto_discover: false

custom filter on exposed params

in your application config ( app.yml ), add the following:

app:
  ch_cms_expose_routing:
    params_blacklist:
      - module
      - action
      - my_param

access routes in browser

It's as simple as calling Routing.generate('route_id', /* your params */).

Routing.generate('route_id', {id: 10});
// will result in /foo/10/bar
Routing.generate('route_id', {"id": 10, "foo":"bar"});
// will result in /foo/10/bar?foo-bar

$.get(Routing.generate('route_id', {"id": 10, "foo":"bar"}));
// will call /foo/10/bar?foo=bar

Documentation

Test suite

You can help us improving code quality by running the JS Test Suite. if you find something wrong, please Report Isssue

TODO

  • cache js routing
  • add simple way to call server with sf_method and csrf_token

chcmsexposeroutingplugin's People

Contributors

fabienpomerol avatar themouette avatar thenodai 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.