Comments (18)
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.
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.
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.
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.
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.
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.
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.
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.
@inmarelibero can you paste your template where you are loading the JS file from the bundle ?
from fosjsroutingbundle.
better: you can have a look at the whole code in https://github.com/inmarelibero/SymfonyBricks repo.
In details:
- toggleUserStarsBrick.js:
javascript file containingRouting.generate()
- app/config/assetic.yml loads
toggleUserStarsBrick.js
- src/Bricks/SiteBundle/Resources/views/Brick/show.html.twig uses
src/Bricks/SiteBundle/Resources/views/macros/macrosBrick.html.twig
- macrosBrick.html.twig is related to
toggleUserStarsBrick.js
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.
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.
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
andfos_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.
I should have resolved with https://github.com/inmarelibero/SymfonyBricks/pull/28
from fosjsroutingbundle.
ok, that PR seems working and it will be merged
many thanks @stof for addressing me to the solution
from fosjsroutingbundle.
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.
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.
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.
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)
- Upgrade guide from v1?
- Importing route and prefix path issue
- webpack-inject-plugin.loader.js?id=webpack-inject-module-1!" contains a reference to the file "fos-router"
- Wrong route in dev env. missing index.php in route HOT 2
- Exception when a route name is a parsable number
- Error: spawn bin/console ENOENT HOT 7
- webpack-inject-plugin > loader-utils vulnerability HOT 4
- Routing isn't finding any routes HOT 2
- webpack problem /FosRouting.js" contains a reference to the file ....
- Symfony 6.3 deprecations
- Symfony 6.3 deprecations when dump routes HOT 1
- Overwriting php location causes console errors that --php is not a valid options
- Document how to install using AssetMapper HOT 10
- Session handling is incompatible with stateless routes introducted with Symfony 6.3
- Run webpack encore and execute php fos:js-routing:dump separately HOT 2
- Support Symfony 7 HOT 6
- 3.4.0 not working with Symfony 6.4 HOT 11
- TS2732: Cannot find module './routes.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.
- Is it possible to `npm install` | `yarn install` the router? HOT 1
- modify dump command to generate export call in js routes file.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fosjsroutingbundle.