Symfony2 to create a simple Web application

Source: Internet
Author: User

symfony2--Creating Bundles    Bundles are like plugins or a full-featured application, and all of the code we develop on the application layer, including: PHP files, configuration files, images, CSS files, JS files, and so on, is included in the Bunde system. Bundles can be created in two ways, one of which isCreate from command line, one isby manually creating the appropriate files and folders。 One: Created from the command line as follows: Figure 1 Executing the above command src/acme/hellobundle is created, specifying the configuration file format used by YML (also using XML and PHP), while automatically app/appkernel.phpadd a line of code that allows the bundle to register to kernel.     Figure 2 symfony2--Creating a simple Web application (configuration files are yml for example) Step 1: Create a routing address     Default configuration file for routing app/config/routing.yml, open the file and you'll see that when you create the bundle, Symfony has added aAcmehellobundleThe portal of the routing configuration file, which tells the symfony where to loadAcmehellobundlerouting configuration. Figure 3 Opening Resources/config/routing.ymldefines the controller that corresponds to the execution of the URL. Figure 4 The routing settings contain two aspects, and path corresponds to the corresponding controller that url,defaults points to the URL execution. The placeholder {name} is a wildcard that matches the URL, such as/HELLO/JC or/hello/jack JC or Jack, and the matching values are passed in as parameters to the Indexaction method. Step 2: Create a controller      The Web application system parses the corresponding URL and is referred to the Symfony framework to execute the appropriate controller (AcmeHelloBundle:Hello:index), the Controller corresponds to the Indexaction method in the Acme\hellobundle\controller\hellotroller class.    Figure 5 Controller is actually a PHP method, which we create, Symfony can execute. Writes the Indexaction method, returns the response object, and finally outputs the response object from the Symfony framework. (The response class is provided by the Symfony framework) Figure 6 where the $name parameter in Indexaction is the placeholder {name},http://localhost/app_dev.php/hello/) in the path in the configuration file Ryan can see the corresponding output. Step 3: Create an Output template

Symfony2 to create a simple Web application

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.