The example in this article describes how to create a page with Symfony2. Share it with everyone for your reference, the details are as follows:
Creating a page in Symfony2 only requires two steps:
1. Create a route: The route defines the URI of your page (such as /about) and specifies it The controller (PHP function) to execute. When the incoming request URL matches this route, Symfony2 will execute the specified controller;
2. Create a controller: The controller is a PHP function that accepts the incoming request and converts it into Symfony2 Response object.
We like this simple implementation because it fits the way the web works. Every web interaction begins with an HTTP request, and it is the application's job to simply interpret the request and return a corresponding HTTP response. Symfony2 follows this principle and provides you with the tools to ensure that your application remains well organized as its users and complexity grow.
“Hello Symfony2” Page
Let’s start with the classic “hello, world” program. When we’re done, the user can get a hello by visiting the following URL:
http://localhost/app_dev.php/hello/Symfony
Actually, you can change Symfony to another name for greetings. To create this page, we only need to follow two simple steps:
This tutorial has assumed that you have downloaded Symfony2 and configured the web server. The above URL assumes localhost points to your new Symfony2 project. For installation details, see Installing Symfony2.
Create a Bundle
Before you begin, you need to create a Bundle. In Symfony2, Bundle is equivalent to a plug-in, and all code in your application needs to be placed in Bundle. A Bundle is just a directory (with a PHP namespace) whose contents are related to a specific function (see Bundle system). Run the following command to create the AcmeStudyBundle (the game built in this chapter).
php app/console Acme/StudyBundle[/]
Next, the following statements were added to the app/autoloader.php file to ensure that the Acme namespace is bootstrapped (see the Autoloading chapter):
$loader->registerNamespaces(array( 'Acme' => __DIR__.'/../src', // ... ));
Finally initialize the Bundle in the registerBundles() method of the app/AppKernel.php file.
// app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Acme\StudyBundle\AcmeStudyBundle(), ); // ... return $bundles; }
Now that you have set up your Bundle, you can build your application in your Bundle.
Create routing
By default, the routing configuration file of Symfony2 is placed in the app/config/routing.yml directory. All configuration files in Symfony2 can also be written in PHP or XML format.
# app/config/routing.yml homepage: pattern: / defaults: { _controller: FrameworkBundle:Default:index } hello: resource: "@AcmeStudyBundle/Resources/config/routing.yml"
The first few lines of the routing configuration file define the code called by the user to request the "/" (home page) resource. What is more interesting is the last part. Imported other routing configuration files located in AcmeStudyBundle.
# src/Acme/StudyBundle/Resources/config/routing.yml hello: pattern: /hello/{name} defaults: { _controller: AcmeStudyBundle:Hello:index }
Routing consists of two basic parts. The pattern determines which URI matches this route, and the defaults array specifies the controller to run. The placeholder {name} in pattern is a wildcard, which indicates that a URI such as /hello/Ryan, /hello/Fabien or other similar matches this route. The {name} placeholder parameter is also sent to the controller so that we can use its value to greet the user.
The routing system has many amazing functions in creating powerful and flexible URL structures for applications. For details, please refer to "Symfony2 Study Notes: Detailed Explanation of System Routing"
Creating Controllers
When a URI like /hello/Ryan is processed by the application, the hello route is matched and the AcmeStudyBundle:Hello:index controller is executed through the Symfony2 framework. The second step in the process of creating the page is to create this controller
In fact, the controller is nothing more than a PHP function that you create and execute through Symfony2. This custom application code uses the request information to build and prepare all Requires resources. Except for some advanced cases, the final output of the controller is the same: a Response object.
// src/Acme/StudyBundle/Controller/HelloController.php namespace Acme\StudyBundle\Controller; use Symfony\Component\HttpFoundation\Response; class HelloController { public function indexAction($name) { return new Response('<html><body>Hello '.$name.'!</body></html>'); } }
The controller is simple, it creates a new Response object whose first parameter is the response content it returns (in this case It's a small HTML page).
Congratulations, just after creating a route and controller, you have got a fully functional page! If your settings are correct, your application will be able to greet you:
http://localhost/app_dev.php/hello/Ryan
An optional but often used step is Create a template.
Controllers are the main entry point and key part when creating pages, more information can be found in the Controllers chapter.
Create Templates
Templates allow you to put all presentation (such as HTML code) into a single file and reuse different parts of the page layout. The following code uses a template to replace the HTML code in the controller.
// src/Acme/StudyBundle/Controller/HelloController.php namespace Acme\StudyBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class HelloController extends Controller { public function indexAction($name) { return $this->render('AcmeStudyBundle:Hello:index.html.twig', array('name' => $name)); // 渲染PHP模板 // return $this->render('AcmeStudyBundle:Hello:index.html.php', array('name' => $name)); } }
In order to use the render() method, you must inherit the Controller class, which adds shortcut methods for some common tasks. The
render() method creates a Response object that is filled with specific content and rendered through a template. Like other controllers, what you end up with is a Response object.
注意,這里有兩種不同渲染模板的例子,缺省情況下,Symfony2支持兩種渲染模板的方式:傳統(tǒng)的PHP模板和簡(jiǎn)潔強(qiáng)大的Twig模板。你可以隨意選擇使用其中的一種,也可以在同一項(xiàng)目中混用它們,這都不成問(wèn)題。
控制器渲染AcmeStudyBundle:Hello:index.html.twig模板,該模板使用以下命名約定:
Bundle名:Controller名:Template名
在本例中,AcmeStudyBundle是Bundle名,Hello是控制器,index.html.twig是模板名。
{# src/Acme/StudyBundle/Resources/views/Hello/index.html.twig #} {% extends '::layout.html.twig' %} {% block body %} Hello {{ name }}! {% endblock %}
讓我們一行行地來(lái):
第2行:extends定義了一個(gè)父模板,模板明確定義了一個(gè)將被替換的布局文件;
第4行:block表示其中的內(nèi)容將會(huì)替換掉名為body的block,如我們所知,它在最終渲染時(shí)將負(fù)責(zé)layout.html.twig中名為body的block的渲染。
父模板::layout.html.twig省略了它的bundle名和控制器名(所以用兩個(gè)冒號(hào)::代替),這意味著該模板在bundle外面,在app目錄中。
{# app/Resources/views/layout.html.twig #} <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>{% block title %}Hello Application{% endblock %}</title> </head> <body> {% block body %}{% endblock %} </body> </html>
基本模板文件定義了HTML布局,并用我們?cè)趇ndex.html.twig模板中定義的名為body的區(qū)塊渲染。這里還定義了一個(gè)名為title的區(qū)塊,我們也可以選擇在index.html.twig模板中定義。由于我們沒(méi)有在子模板中定義title區(qū)塊,所以它還是使用缺省值”Hello Application”。
模板在渲染和組織頁(yè)面內(nèi)容方面的功能非常強(qiáng)大,它可以是HTML標(biāo)識(shí)語(yǔ)言、CSS代碼或者控制器可能需要返回的東東。模板引擎只是達(dá)到目標(biāo)的手段。每個(gè)控制器的目標(biāo)是返回一個(gè)Response對(duì)象,模板雖然強(qiáng)大,但它卻是可選的,它只是為Response對(duì)象創(chuàng)建內(nèi)容的工具而已。
目錄結(jié)構(gòu)
經(jīng)過(guò)前面幾段的學(xué)習(xí),你已經(jīng)理解了在Symfony2中創(chuàng)建和渲染頁(yè)面的步驟,也開(kāi)始明白了Symfony2的組織和結(jié)構(gòu),在本章的最后,你將學(xué)會(huì)在哪兒找到和放置不同類型的文件以及為什么這樣做。
雖然Symfony2的目錄結(jié)構(gòu)相當(dāng)靈活,但在缺省狀態(tài)下,Symfony2還是有著相同的、被推薦的基本目錄結(jié)構(gòu):
app/ : 該目錄包含應(yīng)用程序配置;
src/ : 所有項(xiàng)目的PHP代碼都保存在該目錄下;
vendor/ : 根據(jù)約定放置所有供應(yīng)商的庫(kù)文件;
web/ : 這是web根目錄,包括一些公眾可以訪問(wèn)的文件。
WEB目錄
web根目錄是所有靜態(tài)的、公共文件的家目錄,包括圖像、樣式表和javascript文件,這里也是前端控制器所在的地方。
// web/app.php require_once __DIR__.'/../app/bootstrap.php'; require_once __DIR__.'/../app/AppKernel.php'; use Symfony\Component\HttpFoundation\Request; $kernel = new AppKernel('prod', false); $kernel->handle(Request::createFromGlobals())->send();
前端控制器(在這里是app.php)其實(shí)是一個(gè)PHP文件,在使用Symfony2應(yīng)用程序時(shí)執(zhí)行。它的功能就是使用內(nèi)核類AppKernel,讓應(yīng)用程序自舉。
使用前端控制器意味著要比使用傳統(tǒng)的純PHP程序有著更為靈活多變的URL,當(dāng)使用前端控制器時(shí),URL格式如下所示:
http://localhost/app.php/hello/Ryan
前端控制器app.php被執(zhí)行,URI(/hello/Ryan)通過(guò)路由配置被內(nèi)部路由。如果使用Apache的重寫規(guī)則,你可以在不指定app.php的情況下強(qiáng)制執(zhí)行它:
http://localhost/hello/Ryan
雖然前端控制器在處理請(qǐng)求時(shí)必不可少,但你很少會(huì)去修改甚至想到它,我們只是在環(huán)境一章中簡(jiǎn)要地提及它。
應(yīng)用程序(app)目錄
正如你在前端控制器所看到的那樣,AppKernel類是整個(gè)應(yīng)用程序的主入口,它負(fù)責(zé)所有的配置,它被保存在app/目錄中。
這個(gè)類必須實(shí)現(xiàn)三個(gè)方法,這些方法是Symfony2需要讓應(yīng)用程序了解的。你甚至在一開(kāi)始就無(wú)須擔(dān)心這些方法,因?yàn)镾ymfony2會(huì)智能地為你填充它們:
1、registerBundles(): 返回所有需要在應(yīng)用程序中運(yùn)行的bundle數(shù)組 (參見(jiàn)Bundle系統(tǒng) );
2、registerContainerConfiguration(): 引導(dǎo)應(yīng)用程序的主配置資源文件 (參見(jiàn)應(yīng)用程序配置章節(jié));
3、registerRootDir(): 返回app根目錄 (缺省是 app/)
在日常開(kāi)發(fā)中,你會(huì)經(jīng)常用到app/目錄,你會(huì)在app/config/目錄中修改配置和路由文件(參見(jiàn)應(yīng)用程序配置),也會(huì)使用app/cache/目錄做為應(yīng)用程序的緩存目錄、使用app/logs/目錄做為日志目錄、使用app/Resources/目錄做為應(yīng)用程序級(jí)別的資源目錄。在下面的章節(jié)中你將會(huì)學(xué)到更多關(guān)于這些目錄的內(nèi)容。
自動(dòng)加載
當(dāng)應(yīng)用程序自舉時(shí),將包含一個(gè)特殊的文件:app/autoload.php。該文件負(fù)責(zé)自動(dòng)加載src/和vender/目錄中的所有文件。
因?yàn)橛凶詣?dòng)加載器,你永遠(yuǎn)無(wú)須為使用include或require語(yǔ)句擔(dān)心。Symfony2利用類的名稱空間確定它的位置,并自動(dòng)加載包含你所需的類文件。
$loader->registerNamespaces(array( 'Acme' => __DIR__.'/../src', // ... ));
在這個(gè)配置中,Symfony2將查找src/目錄下Acme名稱空間(假想公司的名稱空間)的所有類。為了能夠自動(dòng)加載,Class Name文件和Path必須遵循同一模式:
Class Name:
Acme\StudyBundle\Controller\HelloController
Path:
src/Acme/StudyBundle/Controller/HelloController.php
app/autoload.php配置自動(dòng)加載器在不同的目錄查找不同的PHP名稱空間,也可以在必要時(shí)自定義。有關(guān)自動(dòng)加載器的更多情況,參見(jiàn)如何自動(dòng)加載類。
源(src)目錄
簡(jiǎn)而言之,src/目錄包括所有在應(yīng)用程序中運(yùn)行的PHP代碼。實(shí)際上在開(kāi)發(fā)時(shí),大部分工作都是在該目錄下完成的。缺省情況下,src/目錄是空的,當(dāng)你開(kāi)始進(jìn)行開(kāi)發(fā)時(shí),你將開(kāi)始填充bundle所在的目錄,該目錄包含你應(yīng)用程序的代碼。
然而bundle究竟是什么呢?
Bundle系統(tǒng)
Bundle與其它軟件中的插件類似,但比它們更好。關(guān)鍵的不同點(diǎn)在于在Symfony2中什么都是bundle,包括框架的核心功能和你為應(yīng)用程序所寫的代碼。在Symfony2中,Bundle是一類公民,這讓使用第三方Bundle的預(yù)建功能包或發(fā)布你自己的Bundle變得十分靈活。它也可以使你很容易地選擇應(yīng)用程序所需功能,并用你自己的方式去優(yōu)化它們。
Bundle簡(jiǎn)單來(lái)說(shuō)就是在一個(gè)目錄里用來(lái)實(shí)現(xiàn)單一功能的結(jié)構(gòu)化文件集。你可以創(chuàng)建BlogBundle、ForumBundle或用戶管理的Bundle(許多都已經(jīng)以開(kāi)源Bundle的形式存在)。每個(gè)目錄都包含與功能相關(guān)的內(nèi)容,如PHP文件、模板、樣式表、Javascripts、測(cè)試等。每個(gè)Bundle都包含某種功能的方方面面,而每種功能都必須在Bundle中實(shí)現(xiàn)。
應(yīng)用程序由在AppKernel類中的registerBundles()方法中定義的Bundle組成:
// app/AppKernel.php public function registerBundles() { $bundles = array( new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), new Symfony\Bundle\SecurityBundle\SecurityBundle(), new Symfony\Bundle\TwigBundle\TwigBundle(), new Symfony\Bundle\MonologBundle\MonologBundle(), new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(), new Symfony\Bundle\DoctrineBundle\DoctrineBundle(), new Symfony\Bundle\AsseticBundle\AsseticBundle(), new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(), // register your bundles new Acme\StudyBundle\AcmeStudyBundle(), ); if (in_array($this->getEnvironment(), array('dev', 'test'))) { $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); } return $bundles; }
通過(guò)registerBundles()方法,你就擁有了應(yīng)用程序所有Bundles的全部控制權(quán)(包含Symfony2的核心Bundle)
無(wú)論Bundle在什么地方,它都可以被Symfony2自動(dòng)加載。舉個(gè)例子,如果AcmeStudyBundle放在src/Acme目錄中,請(qǐng)確保Acme的名稱空間被添加到app/autoload.php文件中,并映射到src/目錄,這樣它就可以被Symfony2自動(dòng)加載了。
創(chuàng)建Bundle
為了向你展示Bundle系統(tǒng)是如何之簡(jiǎn)單,讓我們創(chuàng)建一個(gè)名為AcmeTestBundle的新Bundle,并激活它。
首先,創(chuàng)建一個(gè)src/Acme/TestBundle/ 目錄,并添加一個(gè)名為AcmeTestBundle.php的新文件:
// src/Acme/TestBundle/AcmeTestBundle.php namespace Acme\TestBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; class AcmeTestBundle extends Bundle { }
AcmeTestBundle遵循Bundle命名約定
這個(gè)空類僅僅只是我們需要?jiǎng)?chuàng)建新Bundle的一部分。雖然是空的,但這個(gè)類已經(jīng)足夠強(qiáng)大,并能夠用來(lái)自定義Bundle的行為。
現(xiàn)在我們已經(jīng)創(chuàng)建了我們的Bundle,我們需要通過(guò)Appkernel類激活它:
// app/AppKernel.php public function registerBundles() { $bundles = array( // ... // register your bundles new Acme\TestBundle\AcmeTestBundle(), ); // ... return $bundles; }
雖然目前它還不能做任何事情,但AcmeTestBundle現(xiàn)在已經(jīng)可以使用了。
同樣方便的是,Symfony也提供命令行接口去生成Bundle的基本框架
php app/console init:bundle "Acme\TestBundle" src
生成的Bundle框架包括一個(gè)基本控制器、模板和可自定義的路由資源。接下來(lái)我們將會(huì)討論更多的Symfony2命令行工具。
無(wú)論何時(shí),創(chuàng)建一個(gè)新的Bundle或使用第三方Bundle,都是需要確保該Bundle在registerBundles()中被激活。
Bundle的目錄結(jié)構(gòu)
Bundle的目錄結(jié)構(gòu)是簡(jiǎn)單而靈活的。缺省狀態(tài)下,Bundle系統(tǒng)遵循Symfony2所有Bundle之間保持代碼一致性的約定集。讓我們看看AcmeStudyoverBundle,因?yàn)樗薆undle的大多數(shù)元素:
1、Controller/目錄:包含該Bundle的控制器(如:HelloController.php);
2、Resources/config/目錄:配置目錄,包括路由配置(如:routing.yml);
3、Resources/views/目錄:通過(guò)控制器名組織的模板(如:Hello/index.html.twig);
4、Resources/public/目錄:包含web資源(圖片、樣式表等),并被拷貝或軟鏈接到項(xiàng)目的web/目錄;
5、Tests/目錄:存放該Bundle的所有測(cè)試。
根據(jù)Bundle實(shí)現(xiàn)的功能,它可小可大,它只包含你所需要的文件。
你在本書中還將學(xué)習(xí)到如何持久化對(duì)象到數(shù)據(jù)庫(kù)、創(chuàng)建和驗(yàn)證表單、翻譯你的應(yīng)用程序和編寫測(cè)試等等,它們?cè)贐undle中都有自己的位置和所扮演的角色。
應(yīng)用程序配置
應(yīng)用程序由代表應(yīng)用程序所有功能和特征的Bundle集構(gòu)成。每個(gè)Bundle都可以通過(guò)YAML、XML或PHP編寫的配置文件來(lái)自定義。缺省情況下,主配置文件放置在app/config/目錄中,被命名為config.yml、config.xml或config.php,這取決于你所使用的格式:
# app/config/config.yml framework: charset: UTF-8 secret: xxxxxxxxxx form: true csrf_protection: true router: { resource: "%kernel.root_dir%/config/routing.yml" } validation: { annotations: true } templating: { engines: ['twig'] } #assets_version: SomeVersionScheme session: default_locale: en lifetime: 3600 auto_start: true # Twig Configuration twig: debug: %kernel.debug% strict_variables: %kernel.debug%
我們將在下一節(jié)環(huán)境中展示如何準(zhǔn)確地選擇要引導(dǎo)的文件/格式。
每一個(gè)頂級(jí)條目,如framework或twig都被配置成一個(gè)特定的Bundle。例如,framework被配置成Symfony2的核心FrameworkBundle,并包含路由、模板和其它核心系統(tǒng)的配置。
現(xiàn)在別擔(dān)心配置文件中各段中的特定配置選項(xiàng),配置文件缺省值都是合理的。當(dāng)你瀏覽Symfony2的各部分時(shí),你將學(xué)到每個(gè)部分的特定配置選項(xiàng)。
配置格式
縱觀整個(gè)章節(jié),所有的配置示例都用三種格式(YAML、XML和PHP)展示。它們每個(gè)都有自己的優(yōu)缺點(diǎn),以下是三種格式的說(shuō)明:
1、YAML:簡(jiǎn)單、干凈和易讀
2、XML:有時(shí)比YAML更強(qiáng)大且支持IDE的自動(dòng)完成
3、PHP:非常強(qiáng)大,但與標(biāo)準(zhǔn)配置格式相比易讀性差
環(huán)境
應(yīng)用程序可以在不同的環(huán)境中運(yùn)行。不同的環(huán)境共享相同的PHP代碼(由前端控制 器區(qū)分),但卻有著完全不同的配置。開(kāi)發(fā)環(huán)境記錄警告和錯(cuò)誤,而生產(chǎn)環(huán)境只記錄錯(cuò)誤。在開(kāi)發(fā)環(huán)境中一些文件在每次請(qǐng)求之后被重構(gòu),而在生產(chǎn)環(huán)境中卻被緩存 。所有的環(huán)境都在同一機(jī)制中生活。
雖然創(chuàng)建新的環(huán)境是容易的,但Symfony2項(xiàng)目通常會(huì)從三個(gè)環(huán)境開(kāi)始(開(kāi)發(fā)、測(cè)試和生產(chǎn))。通過(guò)在你瀏覽器中改變前端控制器,你可以很方便地讓應(yīng)用程序在不同的環(huán)境中切換。要將應(yīng)用程序切換到開(kāi)發(fā)環(huán)境,只需要通過(guò)開(kāi)發(fā)前端控制器去訪問(wèn)應(yīng)用程序即可。
http://localhost/app_dev.php/hello/Ryan
如果你想看看你的應(yīng)用程序在生產(chǎn)環(huán)境中的表現(xiàn) ,可以調(diào)用生產(chǎn)前端控制器:
http://localhost/app.php/hello/Ryan
如果你打開(kāi) web/app.php文件,你將發(fā)現(xiàn)它已經(jīng)很明確地被配置成使用生產(chǎn)環(huán)境:
$kernel = new AppCache(new AppKernel('prod', false));
你可以為一個(gè)新的環(huán)境創(chuàng)建一個(gè)新的前端控制器,只需要拷貝該文件,并將prod修改成其它值。
因?yàn)樯a(chǎn)環(huán)境是為速度優(yōu)化的,配置、路由和Twig模板都被編譯成純的PHP類,同時(shí)被緩存 。在生產(chǎn)環(huán)境中改變視圖時(shí),你需要清除這些緩存文件,從而讓它們重構(gòu):
rm -rf app/cache/*
當(dāng)進(jìn)行自動(dòng)測(cè)試時(shí)使用測(cè)試環(huán)境,它并不能從瀏覽器直接訪問(wèn)。參見(jiàn)測(cè)試章節(jié)以得到更多細(xì)節(jié)。
環(huán)境配置
AppKernel類負(fù)責(zé)加載你所選的配置文件:
// app/AppKernel.php public function registerContainerConfiguration(LoaderInterface $loader) { $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml'); }
我們已經(jīng)知道.yml擴(kuò)展名可以轉(zhuǎn)換成.xml或.php,只要你喜歡使用XML或PHP來(lái)寫配置。注意每種環(huán)境也可以加載它們自己的配置文件。下面是為生產(chǎn)環(huán)境準(zhǔn)備的配置文件。
# app/config/config_dev.yml imports: - { resource: config.yml } framework: router: { resource: "%kernel.root_dir%/config/routing_dev.yml" } profiler: { only_exceptions: false } web_profiler: toolbar: true intercept_redirects: true zend: logger: priority: debug path: %kernel.logs_dir%/%kernel.environment%.log
? ?
import關(guān)鍵詞與PHP格式中include語(yǔ)句一樣,都是首先引導(dǎo)主配置文件(config.yml),文件的其它部分是為了增長(zhǎng)的日志和其它有利于開(kāi)發(fā)環(huán)境的設(shè)置而對(duì)缺省配置進(jìn)行的調(diào)整。
在生產(chǎn)環(huán)境和測(cè)試環(huán)境都遵循同樣一個(gè)模型:每個(gè)環(huán)境導(dǎo)入基本配置文件,然后修改它們的配置值去適應(yīng)特殊環(huán)境的需要。
小結(jié)
恭喜你,你現(xiàn)在已經(jīng)明白了Symfony2的基本原理,并驚喜地發(fā)現(xiàn)它是那樣的方便靈活。盡管有許多的功能,但我們可以牢記以下幾個(gè)基本點(diǎn):
1、創(chuàng)建頁(yè)面需要三個(gè)步驟,包括路由、控制器和模板(可選);
2、每個(gè)應(yīng)用程序都應(yīng)該包含四個(gè)目錄:web/(web資源和前端控制器)、app/(配置)、src/(你的Bundle)和vendor/(第三方代碼);
3、Symfony2的每個(gè)功能(包括Symfony2框架核心)都被組織進(jìn)一個(gè)Bundle,Bundle是該功能的結(jié)構(gòu)化文件集;
4、每個(gè)Bundle的配置都存放在app/config目錄中,可以使用YAML、XML和PHP編寫;
5、通過(guò)不同的前端控制器(如:app.php或app_dev.php)和配置文件,每種環(huán)境都可以被訪問(wèn)。
希望本文所述對(duì)大家基于Symfony框架的PHP程序設(shè)計(jì)有所幫助。
更多Symfony2創(chuàng)建頁(yè)面實(shí)例詳解相關(guān)文章請(qǐng)關(guān)注PHP中文網(wǎng)!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)