Symfony2 install and create the first page, symfony2 the first one
1. Installation and Configuration
Reference http://symfony.cn/docs/book/installation.html
Using the Installation tool:
Windows system
Open your command console and execute the following command:
C:"ReadFile (' Http://symfony.com/installer ');" > Symfony.phar
Then, move the downloaded symfony.phar
file to your projects directory and execute it as follows:
C:\> move Symfony.phar C:\projectsc:\projects\> php symfony.phar
To create a symfony app:
Once the Symfony Installer is ready, create your first Symfony application with the new
command:
# Linux, Mac OS X$ symfony New My_project_name# WINDOWSC:CD projects/c:\projects\> php symfony.pha R new My_project_name
To run the Symfony application:
Symfony leverages the internal Web server provided by PHP to run applications while developing them. Therefore, running a Symfony application is a matter of browsing the project directory and executing this command:
CD my_project_name/$ php app/console server:run
2. Catalogue
/app: Cache, configuration file, log and core configuration parameters exist;
/bin: The execution file used for storage;
/SRC: Write your own source code; View files are placed under the View folder
/vendor: Storage of third-party code;
/web/app.php: Single Entry file
Check the configuration:
Command line d:\symfony2.3\app>php check.php
or browser input http://localhost:8000/config.php
3. Write a Hello World page
>php app/console Generate:bundle Create a new bundle
controller/defaultcontroller.php
Phpnamespace Test\webbundle\controller; Use Symfony\bundle\frameworkbundle\controller\controller; Use Sensio\bundle\frameworkextrabundle\configuration\route; Use sensio\bundle\frameworkextrabundle\configuration\template; class extends controller{ /* * @Route ("/hi/{name}") * @Template () * the comment is not useless, it is the use of annotations to dynamically affect program code. @Template () using the default view file public function indexaction ($name) {
the value of//$name is The value of name in route {} return Array $name );//Returns the value of name to the view file }}
Default/index.html.twig
Hello {{Name}}!
Enter Http://localhost:8000/app_dev.php/hi/world in the browser and the page can print out Hello world!
http://www.bkjia.com/PHPjc/1099827.html www.bkjia.com true http://www.bkjia.com/PHPjc/1099827.html techarticle Symfony2 Install and create the first page, Symfony2 first 1, installation and configuration reference http://symfony.cn/docs/book/installation.html using the Installation tool: Windows system Open Your C ...