站內搜尋:Yahoo搜尋如果沒有給完整的網址,請在站內再搜尋一次!

2011-10-20

symfony Jobeet學習紀錄--建立專案(Starting up the Project)--(01/24)

Symfony 的練習範例Jobeet : http://www.symfony-project.org/jobeet/1_4/Doctrine/en/
第一天的課程: Day 1: Starting up the Project


  1. 工作環境需求:web server / PDO相容的資料庫(例如:(MySQL, PostgreSQL, SQLite...等) / php 5.2.4以上的版本。
    我使用Xampp 1.7.7版,php是5.3.8版,符合上述的需求。Xampp解壓縮在c:\xampp 。

  2. 建立專案資料夾:資料夾的路徑、名稱中,不要包含空白字元
    c:\> mkdir c:\dev\sfprojects\jobeet
    c:\> cd c:\dev\sfprojects\jobeet

  3. 下載Symfony:下載網址→http://www.symfony-project.org/installation ,我選擇目前最新的版本 1.4.14,這版本會持續維護到2012年11月
  4. 建立Symfony的解壓縮存放位置:c:\dev\sfprojects\jobeet\lib\vendor>
    將下載取得的symfony-1.4.14.zip,解壓縮到這個資料夾下
    並將解壓縮後的目錄名稱:c:\dev\sfprojects\jobeet\lib\vendor\symfony-1.4.14>
    更改為:c:\dev\sfprojects\jobeet\lib\vendor\symfony>
  5. 建立Jobeet專案
    使用以下指令(參數:generate:project)建立Jobeet專案所需的架構目錄、檔案
    c:\dev\sfprojects\jobeet>c:\xampp\php\php.exe lib\vendor\symfony\data\bin\symfony generate:project jobeet
    • >> dir+      C:\dev\sfprojects\jobeet\apps
    • >> dir+      C:\dev\sfprojects\jobeet\cache
    • >> dir+      C:\dev\sfprojects\jobeet\config
    • >> file+     C:\dev\sfprojects\jobeet\config/ProjectConfiguration.class.php
    • >> file+     C:\dev\sfprojects\jobeet\config/properties.ini
    • >> file+     C:\dev\sfprojects\jobeet\config/rsync_exclude.txt
    • >> dir+      C:\dev\sfprojects\jobeet\data
    • >> dir+      C:\dev\sfprojects\jobeet\data/fixtures
    • >> file+     C:\dev\sfprojects\jobeet\data/fixtures/fixtures.yml
    • >> dir+      C:\dev\sfprojects\jobeet\lib/form
    • >> file+     C:\dev\sfprojects\jobeet\lib/form/BaseForm.class.php
    • >> dir+      C:\dev\sfprojects\jobeet\log
    • >> dir+      C:\dev\sfprojects\jobeet\plugins
    • >> file+     C:\dev\sfprojects\jobeet\symfony
    • >> dir+      C:\dev\sfprojects\jobeet\test
    • >> dir+      C:\dev\sfprojects\jobeet\test/bootstrap
    • >> file+     C:\dev\sfprojects\jobeet\test/bootstrap/functional.php
    • >> file+     C:\dev\sfprojects\jobeet\test/bootstrap/unit.php
    • >> dir+      C:\dev\sfprojects\jobeet\test/functional
    • >> dir+      C:\dev\sfprojects\jobeet\test/unit
    • >> dir+      C:\dev\sfprojects\jobeet\web
    • >> file+     C:\dev\sfprojects\jobeet\web/.htaccess
    • >> dir+      C:\dev\sfprojects\jobeet\web/css
    • >> file+     C:\dev\sfprojects\jobeet\web/css/main.css
    • >> dir+      C:\dev\sfprojects\jobeet\web/images
    • >> dir+      C:\dev\sfprojects\jobeet\web/js
    • >> file+     C:\dev\sfprojects\jobeet\web/robots.txt
    • >> dir+      C:\dev\sfprojects\jobeet\web/uploads
    • >> dir+      C:\dev\sfprojects\jobeet\web/uploads/assets
    • >> tokens    C:/dev/sfprojects/jobeet/config/ProjectConfiguration.class.php
    • >> tokens    C:/dev/sfprojects/jobeet/config/properties.ini
    • >> tokens    C:/dev/sfprojects/jobeet/config/rsync_exclude.txt
    • >> tokens    C:/dev/sfprojects/jobeet/config/ProjectConfiguration.class.php
    • >> tokens    C:/dev/sfprojects/jobeet/config/properties.ini
    • >> tokens    C:/dev/sfprojects/jobeet/config/rsync_exclude.txt
    • >> tokens    C:/dev/sfprojects/jobeet/lib/form/BaseForm.class.php
    • >> file+     C:\dev\sfprojects\jobeet\config/databases.yml
    • >> dir+      C:\dev\sfprojects\jobeet\config/doctrine
    • >> file+     C:\dev\sfprojects\jobeet\config/doctrine/schema.yml
    • >> chmod 777 C:\dev\sfprojects\jobeet\web\uploads
    • >> chmod 777 C:\dev\sfprojects\jobeet\cache
    • >> chmod 777 C:\dev\sfprojects\jobeet\log
    • >> chmod 777 C:\dev\sfprojects\jobeet/symfony
    • >> chmod 777 C:/dev/sfprojects/jobeet/web/uploads/assets
    • >> tokens    C:/dev/sfprojects/jobeet/config/databases.yml
    • >> tokens    C:/dev/sfprojects/jobeet/config/doctrine/schema.yml
    • >> tokens    C:/dev/sfprojects/jobeet/config/ProjectConfiguration.class.php
    • >> tokens    C:/dev/sfprojects/jobeet/config/properties.ini
    • >> tokens    C:/dev/sfprojects/jobeet/config/rsync_exclude.txt
    • >> tokens    C:/dev/sfprojects/jobeet/lib/form/BaseForm.class.php
  6. 簡化輸入的指令
    減重複重複輸入『c:\xampp\php\php.exe lib\vendor\symfony\data\bin\symfony』為『symfony』
    在C:\dev\sfprojects\jobeet\lib\vendor\symfony\data\bin下,有一個symfony.bat的批次檔,把這個批次檔複製到C:\dev\sfprojects\jobeet\目錄下,就可以輸入symfony來代替『c:\xampp\php\php.exe lib\vendor\symfony\data\bin\symfony』這串字串
    在symfony.bat這個批次檔中有提到,要建立一個PHP_COMMAND的環境變數,變數的值是php.exe的所在位置,我php.exe的所在位置是:c:\xampp\php\php.exe
  7. 建立前台應用程式:使用generate:app參數
    c:\dev\sfprojects\jobeet>symfony generate:app frontend
    使用symfony批次檔簡化輸入,產生以下目錄、檔案:
    預設啟用了兩個參數 --escaping-strategy 和 --csrf-secret,可以防止XSS和CSRF攻擊
    • >> dir+      C:\dev\sfprojects\jobeet\apps/frontend\config
    • >> file+     C:\dev\sfprojects\jobeet\apps/frontend\config/app.yml
    • >> file+     C:\dev\sfprojects\jobeet\apps/f...licationConfiguration.class.php
    • >> file+     C:\dev\sfprojects\jobeet\apps/frontend\config/cache.yml
    • >> file+     C:\dev\sfprojects\jobeet\apps/frontend\config/factories.yml
    • >> file+     C:\dev\sfprojects\jobeet\apps/frontend\config/filters.yml
    • >> file+     C:\dev\sfprojects\jobeet\apps/frontend\config/routing.yml
    • >> file+     C:\dev\sfprojects\jobeet\apps/frontend\config/security.yml
    • >> file+     C:\dev\sfprojects\jobeet\apps/frontend\config/settings.yml
    • >> file+     C:\dev\sfprojects\jobeet\apps/frontend\config/view.yml
    • >> dir+      C:\dev\sfprojects\jobeet\apps/frontend\i18n
    • >> dir+      C:\dev\sfprojects\jobeet\apps/frontend\lib
    • >> file+     C:\dev\sfprojects\jobeet\apps/frontend\lib/myUser.class.php
    • >> dir+      C:\dev\sfprojects\jobeet\apps/frontend\modules
    • >> dir+      C:\dev\sfprojects\jobeet\apps/frontend\templates
    • >> file+     C:\dev\sfprojects\jobeet\apps/frontend\templates/layout.php
    • >> tokens    C:/dev/sfprojects/jobeet/apps/frontend/config/settings.yml
    • >> file+     C:\dev\sfprojects\jobeet\web/index.php
    • >> file+     C:\dev\sfprojects\jobeet\web/frontend_dev.php
    • >> tokens    C:\dev\sfprojects\jobeet\web/index.php
    • >> tokens    C:\dev\sfprojects\jobeet\web/frontend_dev.php
    • >> rename    C:\dev\sfprojects\jobeet\apps/f...frontendConfiguration.class.php
    • >> tokens    C:\dev\sfprojects\jobeet\apps/f...frontendConfiguration.class.php
    • >> chmod 777 C:\dev\sfprojects\jobeet\web\uploads
    • >> chmod 777 C:\dev\sfprojects\jobeet\cache
    • >> chmod 777 C:\dev\sfprojects\jobeet\log
    • >> chmod 777 C:\dev\sfprojects\jobeet/symfony
    • >> chmod 777 C:/dev/sfprojects/jobeet/web/uploads/assets
    • >> dir+      C:\dev\sfprojects\jobeet\test/functional/frontend
  8. 目錄讀取權限的調整
    C:\dev\sfprojects\jobeet\cache  C:\dev\sfprojects\jobeet\log 必須使用完全控制(777)的讀取權限。
  9. Web Server網頁伺服器的設定
    在C:\Windows\System32\drivers\etc\目錄下的hosts檔案,加入一行:
    127.0.0.1         jobeet.localhost
    並在httpd.conf檔案的最後面,加入以下內容: (c:\xampp\apache\httpd.conf)
    <VirtualHost 127.0.0.1:80>
      ServerName testproject.localhost
      DocumentRoot "c:\dev\sfprojects\jobeet\web"
      DirectoryIndex index.php
      <Directory "c:\dev\sfprojects\jobeet\web">
        AllowOverride All
        Allow from All
      </Directory>
      Alias /sf "c:\dev\sfprojects\jobeet\lib\vendor\symfony\data\web\sf"
      <Directory "c:\dev\sfprojects\jobeet\lib\vendor\symfony\data\web\sf">
        AllowOverride All
        Allow from All
      </Directory>
    </VirtualHost>
  10. 測試專案
    http://jobeet.localhost
    http://jobeet.localhost/frontend_dev.php

沒有留言:

張貼留言