2014-10-07 65 views
0

我很難決定如何讓網站的網址更清潔。事情是,它是用Angular和Symfony2完成的。 Angular提供前端,而Symfony2提供api。如何正確設置網站的網址

這裏是我的網站的結構:

/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 

現在我得到的網址是www.project.dev/這是家庭,由AngularJS(/前方)呈現,完美的作品,並www.project.dev/ API /應用程序(_dev).PHP/......在Symfony2的渲染,但我想刪除的部分:

app(_dev).php 

我有兩個空的.htaccess中,/和/ API,是否需要使用它們?還是我必須使用Angular-route系統? 我想怎麼做?

回答

0

目前尚不清楚你究竟是如何讓您的Symfony的應用程序安裝,但我會建議使用默認的Symfony目錄結構,因爲它會簡化故障排除問題。默認的目錄結構是這樣的:

/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 

由於您的文檔根目錄指向/web,你可以在那裏目錄爲您的公共資產,如您/js/img/css(或者你可以看看到Assetic,它允許很多很酷的東西,如組合和壓縮js或css)。 /web目錄還包含一個.htaccess文件,以便從URL中刪除app(_dev).php

/api然後可以使用標準的Symfony路由,控制器和視圖創建。您應該閱讀Symfony routing文檔以瞭解其工作原理。這是如何工作的總結是:

  1. 創建路由(如/api/users
  2. 點到控制器的動作路線(見docs)控制器動作
  3. ,返回所需的response

這就是我會建議您構建應用程序。但是,如果你寧願你有結構棒,你將需要一個.htaccess文件在這個post添加到/api目錄(我假設指向/web目錄中的Symfony的應用),並看看什麼.htaccess文件可能包含。

+0

我編輯我的問題,所以你可以更好地瞭解=) – Romain 2014-10-07 17:51:39

+0

你看,我提到的最後一個環節? [這篇文章](http://stackoverflow.com/questions/11149526/symfony2-rewrite-rules-htaccess-app-php)顯示你可以放在.htaccess文件中的網頁目錄 – Sehael 2014-10-07 19:38:11

+0

是的,我曾嘗試過張貼和我想知道,也許它沒有工作,因爲我的具體結構。 – Romain 2014-10-08 07:47:37