Symfony2 install and create the first page, symfony2 the first _php tutorial

Source: Internet
Author: User

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 ...

  • 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.