0

I'm trying to find the best way to deal with dynamic routing generated through an AJAX call with Symfony2.

When a new call is made, I need the current path to be available , along with some dynamic variables that get passed into the path.

Essentially this .

A few answers have suggested putting the route into a variable within each templete , such as

    <script type="text/javascript">
    var productPath = {{ path("acme_myBundle_default_product" , {"magazine" : "bobscheese" , "product" : "chedderfornoobs"}) }};
</script>

The issue here is, the path rely s on variables, that won't exist at runtime (namely $magazine and $product).

A perfect solution would be FOSJsRoutingBundle it seems , but the installation doesn't seem to be up to date with the latest Symfony2 .

Installation runs fine with git submodule add git://github.com/FriendsOfSymfony/FOSJsRoutingBundle.git vendor/bundles/FOS/JsRoutingBundle

but then I think the rest of the ReadMe is out of date, following it gives me a blank screen, with no errors in the log.

So my question is , either , how to install FOSJsRoutingBundle in Symfony2.1.3 , or how best to handle client side generated URLS within Symfony2.

Community
  • 1
  • 1
BobFlemming
  • 2,040
  • 11
  • 43
  • 59

2 Answers2

0

FOSJsRoutingBundle can be normally used in my environment(2.1.3). Does routing go wrong?

Has it set up?

acme_myBundle_default_product:
    pattern:  // ...
    defaults: // ...
    options:
        expose: true
JIGEN
  • 123
  • 4
  • 11
  • in routing.yml? There is nothing like this in any config file as far as I can see? – BobFlemming Oct 30 '12 at 12:52
  • Sorry, I see what you mean now. If I follow the installation instructions, my app doesn't run. No errors are thrown , so I can't get to the point to edit routing.yml with my paths in. – BobFlemming Oct 30 '12 at 12:58
  • If installation is tried, how is this? `php composer.phar require friendsofsymfony/jsrouting-bundle` – JIGEN Oct 30 '12 at 14:59
  • Installing runs fine, its the config that seems to be an issue. – BobFlemming Nov 06 '12 at 17:32
0

I just went down the

<script type="text/javascript">
    var basePath = 'http://www.mybaseurl.com';
</script>

Route. Not as fulfilling, but worked for me in this case.

BobFlemming
  • 2,040
  • 11
  • 43
  • 59