chCmsExposeRoutingPlugin
1.0.0stable
for sf 1.4sf 1.3 MIT
This plugin allow to easily expose all or part of application routes to the client side.
On the client side, routes can be generated as simply as using url_for helper.
When using javascript on the client side, best practices is to enhance the navigation behavior, so most of the time it just requires extracting url from a link href.
Sometimes, it can't be done because the javascript action has no static equivalent.
chCmsExposeRouting is there for you to directly use and generate urls from your symfony routes.
Developers
License
Copyright (c) 2006-2011 Carpe Hora
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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
public function setup()
{
$this->enablePlugins(array('chCmsExposeRoutingPlugin'));
}
```
Then enable chCmsExposeRouting in your application:
```yml
app/{your_app}/config/settins.yml
enabled_modules:
- chCmsExposeRouting
```
you're done !
More conf
You can disable the script auto inclusion by adding the following in your routing.yml
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
yml
app:
ch_cms_expose_routing:
register_routes: false # you will have to register script route manually
and the register your route this way:
yml
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:
```yml
// 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:
yml
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 ):
yml
app:
ch_cms_expose_routing:
auto_discover: false
custom filter on exposed params
in your application config ( app.yml ), add the following:
yml
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 */).
```js
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