Understanding the directory structure of the framework is a way to get started quickly. In a mature framework, each functional module is divided and stored in different directories.
Symfony2 first-level directory structure:
├── app <span>//</span><span>这目录下包含了,配置文件(应用的配置文件会被import到这里面的配置文件中才生效)、缓存的类、缓存的模板</span> <span>├── bin ├── composer.json ├── composer.</span><span>lock</span><span> ├── LICENSE ├── README.md ├── src </span><span>//</span><span>我们编写的应用存放在这个目录下(包含Controller、Model、View、路由配置文件、应用的配置文件等)</span> ├── UPGRADE-<span>2.2</span><span>.md ├── UPGRADE</span>-<span>2.3</span><span>.md ├── UPGRADE</span>-<span>2.4</span><span>.md ├── UPGRADE.md ├── vendor </span><span>//</span><span>Symfony2的核心模块(HttpKernel组件、DependencyInjection组件等)和第三方插件(最常用的第三方插件SonataAdmin)存放在这目录下</span> └── web <span>//</span><span>入口脚本文件存放在这目录下</span>
The following is the main description of Symfony2 secondary directories and subdirectories
Web directory main file description:
├── app_dev.php <span>//</span><span>调试模式下的入口文件(在调试模式下可以额外输出应用的运行信息,包括加载时间、执行的路由、执行sql语句等)</span> ├── apple-touch-<span>icon.png ├── app.php </span><span>//</span><span>生产环境下的入口文件(相当于TP框架index.php作用)</span> <span>├── bundles ├── config.php ├── favicon.ico ├── robots.txt</span>
App directory main directory and file description:
<span>├── AppCache.php ├── AppKernel.php </span><span>//</span><span>入口文件里面会初始化一个AppKernel类,AppKernel类就是在这个文件里面,Appkernel类的主要功能是初始化整个web应用的Bundle。 </span><span>//</span><span>包括Symfony2框架的核心Bundle、第三方插件的Bundle、我们自己编写的应用的Bundle,Bundle在Symfony2里面就相当于一个具有完成 </span><span>//</span><span>某一功能的完整的包,而且我们要用的Bundle都必须在AppKernel类里面注册。</span> <span> ├── autoload.php </span><span>//</span><span>该文件负责自动加载注册在里面的类,通常我们不需要手动修改它</span> <span> ├── bootstrap.php.cache </span><span>//</span><span>Symfony2核心的类的缓存文件,Symfony2框架必须用到的核心的类都会被编写整理到这个文件里面。这样做的目的是减少运行的时候打开 </span><span>//</span><span>文件的个数,提高运行的速度。因为不同的类都被存放在不同的文件里面,如果没有把这些必要的类缓存在一个文件里面,那么我们每次运行 </span><span>//</span><span>都要打开多个文件。如果把这些必要的类整理到一个文件里面,那么我们每次运行这些类就在同一个文件里面了。例如:Request类、Response类、 </span><span>//</span><span>Container类、Kernel类等都会被缓存到这个文件里面。所以,如果我们想在 Request类 里面 echo '在Request里面调试'; 这样的语句,我们就把 </span><span>//</span><span>这语句编写在bootstrap.php.cache文件下的Request类而不是symfony/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Request.php </span><span>//</span><span>里面的Request类。其实symfony/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Request.php里面的Request类就被缓存到bootstrap.php.cache </span><span>//</span><span>里了</span> <span> ├── cache </span><span>//</span><span>缓存目录,按不同模式(生成模式、调试模式)缓存。主要缓存了模板文件、Container类、路由映射相关数据等</span> <span>│ ├── dev │ └── prod ├── check.php ├── config </span><span>//</span><span>存放配置文件的目录,config_dev.yml和config_prod.yml才是被Symfony2框架加载的配置文件。但是为了方便管理,我们会把不同模块的配置 </span><span>//</span><span>编写到不同配置文件中,要使这些配置文件生效,那么我们还需要import它们进config_dev.yml和config_prod.yml。</span> <span> │ ├── config_dev.yml </span><span>//</span><span>调试模式的配置文件 </span> │ ├── config_prod.yml <span>//</span><span>生成模式的配置文件</span> <span>│ ├── config_test.yml │ ├── config.yml </span><span>//</span><span>通用的配置文件,只要import进相应的调试模式下的配置文件,就可以生效</span> │ ├── parameters.yml <span>//</span><span>存放配置文件使用的变量,例如:数据名、数据库密码、数据库host等等</span> <span>│ ├── parameters.yml.dist │ ├── routing_dev.yml </span><span>//</span><span>调试模式下的路由配置文件,我们在src里面编写的路由配置文件需要import到这个文件写才可以生效</span> │ ├── routing.yml <span>//</span><span>通用路由配置文件</span> │ └── security.yml <span>//</span><span>防火墙配置文件,这里的防火墙是web应用防火墙,不是服务器的防火墙,里面配置有角色权限、ACL等,这个文件需要config_*.php import进去才可以生效</span> <span>├── console ├── logs </span><span>//</span><span>Symfony2运行的日志,同理,不同模式下有不同的日志</span> <span>│ ├── dev.log │ └── prod.log ├── phpunit.xml.dist ├── Resources │ └── views └── SymfonyRequirements.php</span>
Directory description of a demo under src:
├── DemoBundle <span>//</span><span>src目录下存放的就是我们应用层的代码,一个功能就可以组织成一个Bundle,例如简单一点的一个购物车功能、复杂一点的 </span><span>//</span><span>一个博客系统都可以组织成一个Bundle。</span> │ ├── AcmeDemoBundle.php <span>//</span><span>还记得app/AppKernel.php吗?每一个Bundle要被Symfony2框架加载并起作用,都需要把Bundle注册到AppKernel类,其实就是 </span><span>//</span><span>把这个文件里面的Bundle类注册到AppKernel类,我们可以手动添加到AppKernel类,也可以通过命令行生成一个Bundle的时候 </span><span>//</span><span>添加到AppKernel里面。</span> <span>│ ├── Command │ ├── Controller </span><span>//</span><span>Controller目录,顾名思义,这个目录下存放的就是Controller类,如果不懂什么是Controller,麻烦请先学习MVC</span> │ ├── DependencyInjection <span>//</span><span>该目录存放对AcmeDemoBundle的扩展</span> │ ├── EventListener <span>//</span><span>该目录存放事件监听器的类,Symfony2框架是一个事件驱动的框架,不同的阶段会触发不同的时间,监听器只要监听相应的事件, </span><span>//</span><span>那么相应事件触发时,这些监听器就会被执行。如果刚接触不是很懂,可以不用太纠结,往后深入会接触到。</span> │ ├── Form <span>//</span><span>该目录存放着表单类。</span> │ ├── Resources <span>//</span><span>该目录存放着Bundle的配置文件、模板文件等</span> <span> ├── config ├── routing.yml </span><span>//</span><span>该文件存放着Bundle的路由配置</span> └── services.xml <span>//</span><span>该文件存放着Bundle的services配置</span> ├── <span>public</span><span> └── views </span><span>//</span><span>该文件夹存放着Bundle的所有模板文件</span> <span>│ ├── Tests │ └── Twig </span>
src: source code location
gen: ID index automatically generated by the system
android4.2.2 and android pr... and libs: here are the jars or libraries that may need to be imported
asset: store external resources
bin: the jar or apt generated by the final program
res: the storage locations for images with different resolutions (starting with drawable); layout files; menu layout files; custom values such as colors, strings, etc. (values Beginning)
androidManifest: android program configuration file, such as permission management, activity registration, etc.;
----Let’s buy this book and read it
/boot: This is where LINUX core and startup-related files are placed. VMLIUZ-XXX in the directory is the kernel. If GRUB is used for startup, there is also a /boot/grub subdirectory in this directory.
/dev: This directory contains all LINUX external devices. Its functions are similar to .sys under DOS and .vxd under Win. In LINUX, devices and files are accessed in the same way. For example: /dev/hda represents the first physical IDE hard disk.
/etc: The files that the system needs to read during the startup process are all in this directory. Such as LILO parameters, user accounts and passwords.
/home: The user’s home directory. For example, if there is a user named buyu, then his home directory is /home/buyu.
/lib: This directory stores the most basic dynamic link shared libraries of the system, similar to the system32 directory under Windows. Almost all applications need to use these shared libraries.
/lost+found: Stores files lost due to illegal shutdown, similar to .chk files under Windows.