Giter Club home page Giter Club logo

Comments (18)

willdurand avatar willdurand commented on August 15, 2024

It's already the case AFAIK

Le 18 nov. 2012 à 12:25, Emanuele Gaspari [email protected] a écrit :

I didn't find in the doc: I was wondering if there's a way to generate routes depending on the environment.

For example, the same

Routing.generate('homepage');
when I'm in the prod environment gives:

/homepage
and when I'm in dev gives:

/app_dev.php/homepage
If this is not possible at the moment, maybe it could be a nice feature


Reply to this email directly or view it on GitHub.

from fosjsroutingbundle.

inmarelibero avatar inmarelibero commented on August 15, 2024

I didn't have a look at the source code, but the routes generated do not take care of app_dev.php.

From what I experienced, generated urls are like

/en/homepage
or
/homepage

even if I'm in app_dev.php. I'll get a deeper look to verify that. thanks

from fosjsroutingbundle.

willdurand avatar willdurand commented on August 15, 2024

Well, it should use a prefix. Look at the test suite maybe.

Le 18 nov. 2012 à 18:32, Emanuele Gaspari [email protected] a écrit :

I didn't have a look at the source code, but the routes generated do not take care of app_dev.php.

From what I experienced, generated urls are like

/en/homepage
or
/homepage
even if I'm in app_dev.php. I'll get a deeper look to verify that. thanks


Reply to this email directly or view it on GitHub.

from fosjsroutingbundle.

inmarelibero avatar inmarelibero commented on August 15, 2024

For what I understood, prefix is used for route names. looking at routes.js:

var prefixedName = this.context_.prefix + name;
if (!this.routes_.containsKey(prefixedName)) {
    // Check first for default route before failing
    if (!this.routes_.containsKey(name)) {
      throw new Error('The route "' + name + '" does not exist.');
    }
} else {
  name = prefixedName;
}

But I resolved though the setBaseUrl() function:

Routing.setBaseUrl('/app_dev.php');

var url = Routing.generate('user_brick_toggle_star', {'brick_id': brick_id});

in this way the generated url is

/app_dev.php/en/brick/toggle-star/2

instead of

/en/brick/toggle-star/2

This solves it, but all this code is inside a .js file, I cannot set the base url depending on the environment.

Would it be the case to go deep in such feature? loading the environment related controller should be done by default.

from fosjsroutingbundle.

inmarelibero avatar inmarelibero commented on August 15, 2024

maybe the configuration can be tweaked, such as:

# app/config/routing.yml
fos_js_routing:
    [...]
    environments:
        dev:
            baseUrl: app_dev.php
        test:
            baseUrl: app_test.php
        [custom env.]:
            baseUrl: [custom controller].php

by default the baseUrl for prod is ""

from fosjsroutingbundle.

willdurand avatar willdurand commented on August 15, 2024

The base_url variable should have app_dev.php as value in dev env. See: https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/blob/master/Controller/Controller.php#L81

from fosjsroutingbundle.

inmarelibero avatar inmarelibero commented on August 15, 2024

It's still not working for me, and I made a standard installation. Am I the only one experiencing this?

Following the line you indicated, the work should be done by

public function getBaseUrl()
{
    return $this->router->getContext()->getBaseUrl() ?: '';
}

in ExposedRoutesExtractor.php, right?

I don't kwon why but it does not work properly, I'll have a deeper look. maybe you could leave this issue open for a while, for someone more experiences this. thanks

from fosjsroutingbundle.

inmarelibero avatar inmarelibero commented on August 15, 2024

I'm still experiencing this, in another project with a fresh installation on another server.
Would you please repoen this issue, to verify if this is happening to someone else?

from fosjsroutingbundle.

stof avatar stof commented on August 15, 2024

@inmarelibero can you paste your template where you are loading the JS file from the bundle ?

from fosjsroutingbundle.

inmarelibero avatar inmarelibero commented on August 15, 2024

better: you can have a look at the whole code in https://github.com/inmarelibero/SymfonyBricks repo.

In details:

As you can see at line toggleUserStarsBrick.js#L16, if I don't set Routing.setBaseUrl('/app_dev.php'); it doesn't add app_dev.php if environment is dev

Is it enough? I can illustrate better if necessary, thanks @stof

from fosjsroutingbundle.

stof avatar stof commented on August 15, 2024

hmm, the issue is that you are using a static file for the routes, and using the same file fopr both environment, which is not the way we document.
You need to dump a different route file for each environment (and then using the Assetic variables to select the right file based on the environment)

from fosjsroutingbundle.

inmarelibero avatar inmarelibero commented on August 15, 2024

ah ok, it makes sense.

How could I dump a different route for each environment? I'm looking doc/README.markdown#fosjs-routingdump. Also, the usage of fos:js-routing:dump is:

Usage:
    fos:js-routing:dump [--callback="..."] [--target[="..."]] [--locale[="..."]]

and it seems not possible to specify an environment. Could you give me some doc to read about this?

For what I understand I should do the following (more or less):

  • create fos_js_routes.prod.js and fos_js_routes.dev.js
  • use Assetic variables in this way (looking here):
assetic:
    [...]
    variables:
        environments: [prod, dev]

    assets:
        javascripts:
            inputs:
                [...]
                - %kernel.root_dir%/../web/js/fos_js_routes.{environment}.js

from fosjsroutingbundle.

inmarelibero avatar inmarelibero commented on August 15, 2024

I should have resolved with https://github.com/inmarelibero/SymfonyBricks/pull/28

from fosjsroutingbundle.

inmarelibero avatar inmarelibero commented on August 15, 2024

ok, that PR seems working and it will be merged

many thanks @stof for addressing me to the solution

from fosjsroutingbundle.

ikodev avatar ikodev commented on August 15, 2024

Hi, I'm experiencing the same issue. @inmarelibero could you explain me how did you process to generate URLs for app_dev.php env ? I understand the solution described by @stof but I never have my routes prefixed by "app_dev.php/". I look at SymfonyBricks repo but can't find solution. Thank you ! ;)

from fosjsroutingbundle.

inmarelibero avatar inmarelibero commented on August 15, 2024

hi, did you give a look at https://github.com/inmarelibero/SymfonyBricks/commit/e13373cfb085cc459afc128bc1bbd97e276b9531?

I think answer is here. I don't remember exactly what I did to resolve this. If you don't succeed in resolving it, I'll give a look

from fosjsroutingbundle.

ikodev avatar ikodev commented on August 15, 2024

Hi @inmarelibero, thank you for your help. I finally managed to use FOSJsRouting in both environments :) but for instance it works only if I use the call of "routing?callback=fos.Router.setData" script in order to get routes on the fly.

from fosjsroutingbundle.

inakiarroyo avatar inakiarroyo commented on August 15, 2024

I have the same issue, when i'm in 'dev' enviroment, the FOSJsRoutingBundle generate a prod 'url',
I'm working with 'Symfony 2.5.4' and "friendsofsymfony/jsrouting-bundle": "@stable".
Any new solution?

from fosjsroutingbundle.

Related Issues (20)

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.