symfony2 安裝並建立第一個頁面,symfony2第一個_PHP教程

來源:互聯網
上載者:User

symfony2 安裝並建立第一個頁面,symfony2第一個


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:\projectsc:\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# Windowsc:\> 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

phpnamespace 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!

http://www.bkjia.com/PHPjc/1099827.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1099827.htmlTechArticlesymfony2 安裝並建立第一個頁面,symfony2第一個 1、安裝和配置 參考 http://symfony.cn/docs/book/installation.html 使用安裝工具: windows系統 Open your c...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.