0

I'm having trouble to decide how I should do to make my websites urls cleaner. The thing is, it's done with Angular AND Symfony2. Angular providing the front, and Symfony2 providing the api.

Here's my website's structure :

/api
    /app => configurations go here
    /bin => binaries
    /src => your bundles/MVC code
    /vendor => Symfony and 3rd party bundles
    /web => this is where the web server document root should be pointed to

/front
    /api -> Symlink to /api/web in the symfony part, working, but with app.php and app_dev.php
    /css -> frontend CSS
    /img -> frontend Images
    /js  -> frontend JS for AngularJS
    /lib
    /partials -> html templates used by AngularJS
    index.html

Now the urls I get are www.project.dev/ which is home, rendered by AngularJS (/front), works perfectly, and www.project.dev/api/app(_dev).php/... rendered in Symfony2 but I want to remove the part :

app(_dev).php

I have two empty .htaccess, in / and in /api, do I need to use them ? Or do I have to use the Angular-route system ? How am I suppose to do it ?

Romain
  • 3,586
  • 7
  • 31
  • 52

1 Answers1

0

It's not clear how exactly you have your Symfony application setup, but I would recommend using the default Symfony directory structure, as it will simplify troubleshooting problems. The default directory structure is something like this:

/Symfony
    /app => configurations go here
    /bin => binaries
    /src => your bundles/MVC code
    /vendor => Symfony and 3rd party bundles
    /web => this is where the web server document root should be pointed to

Since your document root is pointed to /web, you can have directories in there for your public assets, such as your /js, /img, and /css (Or you can look into Assetic, it allows lots of cool things like combining and compressing js or css.). The /web directory also has a .htaccess file included so that the app(_dev).php is removed from the URL.

Your /api can then be built using the standard Symfony routing, controllers, and views. You should read the Symfony routing documentation to get a grasp of how that works. A summary of how this works is:

  1. create the route (ex. /api/users)
  2. point the route to a Controller action (see the docs)
  3. in the controller action, return the desired response

That's how I would recommend you structure your application. But if you would rather stick with the structure that you have, you will need to add a .htaccess file to the /api directory (which I assume points to the /web directory of the Symfony application), and take a look at this post for what the .htaccess file could contain.

Community
  • 1
  • 1
Sehael
  • 3,678
  • 21
  • 35
  • I edited my question so you could understand better =) – Romain Oct 07 '14 at 17:51
  • did you look at the last link that I referred to? [This post](http://stackoverflow.com/questions/11149526/symfony2-rewrite-rules-htaccess-app-php) shows what you can put in the .htaccess file in the web directory – Sehael Oct 07 '14 at 19:38
  • Yeah, I tried that before posting and I was wondering that maybe it didn't work because of my specific structure. – Romain Oct 08 '14 at 07:47
  • It's possible. I have never tried using a symfony application where the `/web` directory is not at the document root of the site. Is there a specific reason that you don't want to use Symfony for the whole application? – Sehael Oct 08 '14 at 15:04
  • Well, I think using AngularJS as a templating system, over a Symfony RESTFul API seems a very good idea. I want to see it through, as the results I'm getting now are really promising. – Romain Oct 08 '14 at 15:09
  • I agree, it is a great idea. It can be done using Symfony for serving the AngularJS templates/views as well. But let us know how it goes with your setup. – Sehael Oct 08 '14 at 15:35