Symfony2 using assetic with Angular HTML5 routes
Asked Answered
D

2

5

I use an angular front end with Symfony. When I declare my $routeProvider I have to include my /app_dev.php/ becuase I set the html 5 mode to true: $locationProvider.html5Mode(true);.

$routeProvider.when('/app_dev.php/admin', 
                    {templateUrl: 'index.html', controller:   AdminCtrl})
              .when('/app_dev.php/admin/schedule/', 
                    {templateUrl: 'schedule.html', controller: ScheduleCtrl})
              .otherwise('/app_dev.php/admin');
$locationProvider.html5Mode(true);

vs

$routeProvider.when('/admin', 
                    {templateUrl: 'index.html', controller:   AdminCtrl})
              .when('/admin/schedule/', 
                    {templateUrl: 'schedule.html', controller: ScheduleCtrl})
              .otherwise('/admin');
$locationProvider.html5Mode(true);

The problem is I have to remember to change those routes back when I want to use the production environment.

I there a good way to handle this perhaps with assetic when I do a dump to detect I am doing the dump for the dev vs prod or do I just have to painfully remember to change the paths for the target envirnment?

Thanks

Dressage answered 19/8, 2013 at 17:27 Comment(0)
P
6

Try to use FOSJsRoutingBundle. This bundle allows you to expose your routing in your JavaScript code. That means you'll be able to generate URL with given parameters like you can do with the Router component provided in the Symfony2 core. https://github.com/FriendsOfSymfony/FOSJsRoutingBundle

Perpendicular answered 22/8, 2013 at 16:23 Comment(1)
I looked at the module and seems to be a far better solution, by what I read, it is my understanding that the generated routes work similar to the path generation in twig and controllers. This would be a much better way to solve the problem. I will run some test with this module and see how that works out for me.Dressage
Y
2

You could use different rewrite rules in your .htaccess. And then gitignore the file. So that on your localhost its always routed through app_dev.php and on prod through app.php. In order to help you dumping the routes, Symfony2 has a command: http://symfony.com/doc/current/cookbook/configuration/apache_router.html

Year answered 19/8, 2013 at 19:11 Comment(2)
That is an interesting solution. I will look into it. Currently, for development, I don't use apache but rather the built in PHP server and writing a rewrite script that imitates that is not desirable right now.Dressage
But then you will have to maintain your routes and .htaccessHers

© 2022 - 2024 — McMap. All rights reserved.