1、安裝和配置 參考 http://symfony.cn/docs/book/installation.html 使用安裝工具: windows系統 Open your command console and execute the following command: c:\> php -r "r
1、安裝和配置
參考 http://symfony.cn/docs/book/installation.html
使用安裝工具:
windows系統
Open your command console and execute the following command:
c:\> php -r "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:\projects
c:\projects\> php symfony.phar
創建symfony應用:
Once the Symfony Installer is ready, create your first Symfony application with the new
command:
# Linux, Mac OS X
$ symfony new my_project_name
# Windows
c:\> cd projects/
c:\projects\> php symfony.phar new my_project_name
運行symfony應用:
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、目錄
/app:存在緩存、配置文件、日誌及核心配置參數;
/bin:存放用到的執行文件;
/src:自己編寫的源代碼;視圖文件放在view文件夾下
/vendor:存放第三方代碼;
/web/app.php:單一入口文件
檢查配置:
命令行 d:\symfony2.3\app>php check.php或 瀏覽器輸入http://localhost:8000/config.php
3、編寫一個hello world頁面
>php app/console generate:bundle 創建一個新的bundle
Controller/DefaultController.php
<?php namespace Test\WebBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; class DefaultController extends Controller { /** * @Route("/hi/{name}") * @Template() */ //以上註釋並不是沒有用,是利用註釋動態影響程式代碼.@Template()使用預設視圖文件 public function indexAction($name) {
//$name的值為路由{}中name的值 return array('name' => $name);//返回name的值給視圖文件 } }
Default/index.html.twig
Hello {{ name }}!
瀏覽器中輸入http://localhost:8000/app_dev.php/hi/world,頁面中可以列印出Hello world!