开发者

Understanding architecture and folder structure in Symfony2?

I'm completely new to Symfony 2 and i can't really understand the folder structure and开发者_运维知识库 organization of a project. I know what a bundle is, but what is unclear to me is:

  • what's the main directory (the directory to be copied on the web server for deployment)
  • where assets (css, javascript) should be placed
  • if (and how) environment should be changed when publishing my website

I've already read the book on Symfony website and i can't find those answers.


  • The web root of a Symfony2 app is the 'web' directory, but when you push to production the entire symfony2 project should be pushed not just the web root.

From the symfony2 book

app/: This directory contains the application configuration;
src/: All the project PHP code is stored under this directory;
vendor/: Any vendor libraries are placed here by convention;
web/: This is the web root directory and contains any publicly accessible files;

  • The assets should be kept in the bundles 'Resources/public/[css/js/images]' folders. From here you would have to copy or symlink those directories into the web root to make them accessible. Symfony2 comes with a command line utility located in the 'app' directory. app/console assets:install web --symlink command executed from the command line of your symfony2 project root will install all of the bundle's assets for you.

  • To change environments and you are using Apache you would use a .htaccess file and mod_rewrite to select which environment you would want to use

    RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /app.php [QSA,L]
    

    using /app.php puts me into production mode and using /app_dev.php would put me in development mode.


  • The main directory contains the app folder.
  • The assets should be placed in the bundles folder they're related to. This folder is named "public".
  • Read this. All you need to do is remove the app_dev.php file.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜