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