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

顯示具有 Symfony 標籤的文章。 顯示所有文章
顯示具有 Symfony 標籤的文章。 顯示所有文章

2011-10-21

symfony Jobeet學習紀錄--Jobeet網站的資料模型(The Data Model)--(03/24)

Symfony 的練習範例Jobeet : http://www.symfony-project.org/jobeet/1_4/Doctrine/en/
第三天的課程: Day 3: The Data Model

在第三天的課程安排中,將可滿足渴望使用文字編輯器編寫PHP程式碼的需求。
接下來的內容有:定義Jobeet的資料模型、使用ORM與資料庫互動、建立應用程式的第一個模組。但這些功能並不需要很多的PHP程式碼。

資料關聯模式(The Relational Model)
在第二天的課程中,有提到Jobeet專案的主要物件有:求才資料(Job)、進階使用(Affiliate)、工作分類(Category),右圖是這些物件的關聯圖。
為了滿足系統在公佈天數等需求,使用了created_at欄位,當資料新增時,會以系統時間紀錄在created_at欄位。同樣的道理,當有資料更新時,會以當時的系統時間紀錄在Updated_at。

資料綱要(The Schema)
很明顯這裡需要使用一個關聯式資料庫來存放求才資料(Job)、進階使用(Affiliate)、工作分類(Category)等資料。
Symfony是一個物件導向的架構,因此盡可能以物件的方式來操作系統。例如:會以物件的方式方來代替寫SQL語法取得資料。
所以關聯式的資料庫必須對應成物件模式,這可以透過ORM(Object-relational Mapping)的工具來達成,Symfony預設提供了Propel和Doctrine兩種ORM的工具,這裡要用的是Doctrine。
ORM需要描述資料表及資料表間的關係,藉此來建立類別的關聯。描述資料綱要(Schema)有兩種方式:檢視已存在的資料庫或以人工的方式來建立。
因Jobeet的資料庫還不存在,在對Jobeet資料庫還不知悉的情況下,就使用以下的內容來建立資料綱要(Schema), config/doctrine/schema.yml

# config/doctrine/schema.yml
JobeetCategory:
  actAs: { Timestampable: ~ }
  columns:
    name: { type: string(255), notnull: true, unique: true }
 
JobeetJob:
  actAs: { Timestampable: ~ }
  columns:
    category_id:  { type: integer, notnull: true }
    type:         { type: string(255) }
    company:      { type: string(255), notnull: true }
    logo:         { type: string(255) }
    url:          { type: string(255) }
    position:     { type: string(255), notnull: true }
    location:     { type: string(255), notnull: true }
    description:  { type: string(4000), notnull: true }
    how_to_apply: { type: string(4000), notnull: true }
    token:        { type: string(255), notnull: true, unique: true }
    is_public:    { type: boolean, notnull: true, default: 1 }
    is_activated: { type: boolean, notnull: true, default: 0 }
    email:        { type: string(255), notnull: true }
    expires_at:   { type: timestamp, notnull: true }
  relations:
    JobeetCategory: { onDelete: CASCADE, local: category_id, foreign: id, foreignAlias: JobeetJobs } 
 
JobeetAffiliate:
  actAs: { Timestampable: ~ }
  columns:
    url:       { type: string(255), notnull: true }
    email:     { type: string(255), notnull: true, unique: true }
    token:     { type: string(255), notnull: true }
    is_active: { type: boolean, notnull: true, default: 0 }
  relations:
    JobeetCategories:
      class: JobeetCategory
      refClass: JobeetCategoryAffiliate
      local: affiliate_id
      foreign: category_id
      foreignAlias: JobeetAffiliates
 
JobeetCategoryAffiliate:
  columns:
    category_id:  { type: integer, primary: true }
    affiliate_id: { type: integer, primary: true }
  relations:
    JobeetCategory:  { onDelete: CASCADE, local: category_id, foreign: id }
    JobeetAffiliate: { onDelete: CASCADE, local: affiliate_id, foreign: id }

在資料庫設定 database.yml 已經OK的情況下(待會才會進行這個步驟),可以使用 symfony doctrine:build-schema來建立資料綱要(schema)。
YAML的參考資料:
  1. http://yaml.org/
  2. http://components.symfony-project.org/yaml/documentation

資料庫的準備
首先準備好一個命名為jobeet的MSQL資料庫。
使用以下指令,讓Jobeet專案,可以使用jobeet資料庫:
symfony configure:database "mysql:host=localhost;dbname=jobeet" root password
在configure:database這個任務中,用了三個參數:PDO DSN、資料庫帳號、密碼
執行configure:database後,資料庫的設定會存放在 config/database.yml,這個設定檔不一定要使用configure:database來產生,也可以自行編輯建立。

使用ORM(Object-relational Mapping)
前面已經建立資料庫的描述 config/doctrine/schema.yml ,接著要使用Doctrine內建的功能來產生建立資料表所需的SQL敘述。
在產生SQL敘述前,要先從綱要檔(Schema)建立模型類別(Model):
c:\dev\sfprojects\jobeet>symfony doctrine:build --model

>> doctrine  generating model classes
>> file+     C:\Users\Hannibal\AppData\Local\Temp/doctrine_schema_52712.yml
>> tokens    C:/dev/sfprojects/jobeet/lib/mo...trine/JobeetAffiliate.class.php
>> tokens    C:/dev/sfprojects/jobeet/lib/mo.../JobeetAffiliateTable.class.php
>> tokens    C:/dev/sfprojects/jobeet/lib/mo...ctrine/JobeetCategory.class.php
>> tokens    C:/dev/sfprojects/jobeet/lib/mo...beetCategoryAffiliate.class.php
>> tokens    C:/dev/sfprojects/jobeet/lib/mo...ategoryAffiliateTable.class.php
>> tokens    C:/dev/sfprojects/jobeet/lib/mo...e/JobeetCategoryTable.class.php
>> tokens    C:/dev/sfprojects/jobeet/lib/model/doctrine/JobeetJob.class.php
>> tokens    C:/dev/sfprojects/jobeet/lib/mo...ctrine/JobeetJobTable.class.php
>> tokens    C:/dev/sfprojects/jobeet/lib/mo...e/BaseJobeetAffiliate.class.php
>> tokens    C:/dev/sfprojects/jobeet/lib/mo...se/BaseJobeetCategory.class.php
>> tokens    C:/dev/sfprojects/jobeet/lib/mo...beetCategoryAffiliate.class.php
>> tokens    C:/dev/sfprojects/jobeet/lib/mo...ne/base/BaseJobeetJob.class.php
>> autoload  Resetting application autoloaders


模型類別(Model Classes)建立後,接著就可以來產生SQL敘述了:
c:\dev\sfprojects\jobeet>symfony doctrine:build --sql

>> doctrine  generating model classes
>> file+     C:\Users\Hannibal\AppData\Local\Temp/doctrine_schema_81084.yml
>> tokens    C:/dev/sfprojects/jobeet/lib/mo...e/BaseJobeetAffiliate.class.php
>> tokens    C:/dev/sfprojects/jobeet/lib/mo...se/BaseJobeetCategory.class.php
>> tokens    C:/dev/sfprojects/jobeet/lib/mo...beetCategoryAffiliate.class.php
>> tokens    C:/dev/sfprojects/jobeet/lib/mo...ne/base/BaseJobeetJob.class.php
>> autoload  Resetting application autoloaders
>> file-     C:/dev/sfprojects/jobeet/cache/.../config/config_autoload.yml.php
>> doctrine  generating sql for models
>> dir+      C:\dev\sfprojects\jobeet\data/sql
>> doctrine  Generated SQL successfully for models
以上所產生的SQL敘述語法,存放在 sql\data 目錄下

上述的作業只是產生要建立資料表的SQL敘述語法,建立資料表:

c:\dev\sfprojects\jobeet>symfony doctrine:insert-sql
>> doctrine  creating tables
>> doctrine  created tables successfully



Symfony內建有Help的功能,可以透過 symfony help <task> 取得相關內容
例如:symfony help doctrine:insert-sql

在上述的symfony doctrine:build --model作業裡,所產生的php檔案(位於 lib/model )是用來跟資料庫互動的。
瀏覽這些php檔,可以發現每個資料表有三個類別(class)檔案,以jobeet_job資料表為例:

  1. JobeetJob.class.php:這個類別(class)的一個物件(object),代表jobeet_job資料表的一筆資料。這個類別預設是空的。
    class JobeetJob extends BaseJobeetJob {  }
  2. BaseJobeetJob.class.php:這是JobeetJob的父類別(parent class),每次執行 doctrine:build --model 時,這個類別會被複寫(overwritten),所有的作業會在JobeetJob類別中完成。
  3. JobeetJobTable.class.php:這個類別用來定義方法(Methods),主要用來傳送JobeetJob的物件值。這個類別預設是空的。
    class JobeetJobTable extends Doctrine_Table {
        /**
         * Returns an instance of this class.
         *
         * @return object JobeetJobTable
         */
        public static function getInstance()     {
            return Doctrine_Core::getTable('JobeetJob');
        }
    }

資料欄位的值可以用模型物件(model object)中的存取子(accessor, get*())及更動子(mutator, set*())來操作。例如:
$job = new JobeetJob();
$job->setPosition('Web developer');
$job->save();
echo $job->getPosition();
$job->delete();


也可以直接定義外來鍵(foreign key),把物件連結在一起。例如:
$category = new JobeetCategory();
$category->setName('Programming');
$job = new JobeetJob();
$job->setCategory($category);

在ORM這個段落中的作業項目:doctrine:build --model / doctrine:build --sql / doctrine:insert-sql,以及後續要進行的其他項目:產生表單(form)、資料驗證(validator)...
,可以用doctrine:build --all來代替。例如:
symfony doctrine:build --all --no-confirmation

起始資料(The Initial Data)
經過以上的作業項目,已經在資料庫建立資料表,但資料表中還沒有任何資料。任何的網頁應用程式都會有以下三種資料:

  1. 起始資料(Initial Data):起始資料是應用程式作業所需要的,例如:Jobeet網站需要一些工作分類(category)的起始資料,也需要讓管理者可以登入後台的管理資料。
  2. 測試資料(Test Data):程式開發人員需要一些測試資料來測試網站應用程式。
  3. 使用者資料(User data):使用者在日常作業所產生的資料。
每一次Symfony在資料庫中重新建立資料表,都會清空資料,為使資料庫中的起始資料可以保留下來,可以用php程式碼、在MySQL中執行SQL 敘述語法,這些需求是很普遍常見的,有一個更好的方法,可以用symfony來做。
在 data/fixtures/ 建立 YAML固定檔案,使用doctrine:data-load來將資料載入資料庫中。例如:
# data/fixtures/categories.yml
JobeetCategory:
  design:
    name: Design
  programming:
    name: Programming
  manager:
    name: Manager
  administrator:
    name: Administrator
# data/fixtures/jobs.yml
JobeetJob:
  job_sensio_labs:
    JobeetCategory: programming
    type:         full-time
    company:      Sensio Labs
    logo:         sensio-labs.gif
    url:          http://www.sensiolabs.com/
    position:     Web Developer
    location:     Paris, France
    description:  |
      You've already developed websites with symfony and you want to work
      with Open-Source technologies. You have a minimum of 3 years
      experience in web development with PHP or Java and you wish to
      participate to development of Web 2.0 sites using the best
      frameworks available.
    how_to_apply: |
      Send your resume to fabien.potencier [at] sensio.com
    is_public:    true
    is_activated: true
    token:        job_sensio_labs
    email:        job@example.com
    expires_at:   '2010-10-10'
  job_extreme_sensio:
    JobeetCategory:  design
    type:         part-time
    company:      Extreme Sensio
    logo:         extreme-sensio.gif
    url:          http://www.extreme-sensio.com/
    position:     Web Designer
    location:     Paris, France
    description:  |
      Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
      eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
      enim ad minim veniam, quis nostrud exercitation ullamco laboris
      nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
      in reprehenderit in.
      Voluptate velit esse cillum dolore eu fugiat nulla pariatur.
      Excepteur sint occaecat cupidatat non proident, sunt in culpa
      qui officia deserunt mollit anim id est laborum.
    how_to_apply: |
      Send your resume to fabien.potencier [at] sensio.com
    is_public:    true
    is_activated: true
    token:        job_extreme_sensio
    email:        job@example.com
    expires_at:   '2010-10-10'

其中jobs.yml這個固定檔案會參考兩張圖片,分別位於以下網址,下載存到 web/uploads/jobs/目錄下
http://www.symfony-project.org/get/jobeet/sensio-labs.gif 
http://www.symfony-project.org/get/jobeet/extreme-sensio.gif

位於 data/fixtures的固定檔案,使用YAML格式編碼,定義了模型物件(object model),以標籤的方式建立唯一的名稱(在jobs.yml中定義了:job_sensio_labs 及 job_extreme_sensio),標籤的最大用處是建立物件的連結關係,不必定義主鍵(primary key),例如:job_sensio_labs的求才工作分類是programming,這個標籤(label)是設定在Programming工作分類。
在YAML檔案中,如果一個字串是由多行文字所組成,必須使用pine字元(|)來串接多行字串,成為一個字串。

雖然一個固定檔案(fixture file)可以包含一到數個模型(Model),這裡採用的方式是一個固定檔案對應一個模型的作法。
Propel requires that the fixtures files be prefixed with numbers to determine the order in which the files will be loaded.
With Doctrine this is not required as all fixtures will be loaded and saved in the correct order to make sure foreign keys are set properly.

固定檔案(fixture file)中,並不需要定義所有的欄位值,symfony可以帶入database schema中的預設值,且當symfony使用doctrine來載入資料到資料庫時,所有內建的行為(built-in behavior)(例如:自動記載產生時生、更新時間)和自訂的行為(custom behavior)都會啟動。
載入起始資料到資料庫的指令 : symfony doctrine:data-load

c:\dev\sfprojects\jobeet>symfony doctrine:data-load
>> doctrine  Loading data fixtures from "C:\...fprojects\jobeet\data/fixtures"
>> doctrine  Data was successfully loaded

可以使用doctrine:build --all --and-load 來代替 doctrine:build --all 和 doctrine:data-load這兩項作業
使用symfony dotrine:build --all --and-load會產生forms, filters, models,並刪除資料庫、重建資料表。

使用瀏覽器查看實際的狀況(See it in Action in the Browser)
接下來是如何顯示工作列表、如何編輯現存的求才資料、如何刪除一筆求才資料,如第一天的進度,Symfony專案是由應用程式組成,每一應用程式可細分為模組(modules),模組中包含表達程式特性的PHP程式碼(例如API模組),或使用者可以在模型物件中進行的各項操作(例如:求財模型Job Model)。
Symfony可以從指定的模型中,自動產生模組,並提供基本的操作
symfony doctrine:generate-module --with-show --non-verbose-templates frontend job JobeetJob

>> dir+      C:\dev\sfprojects\jobeet\apps\frontend\modules/job\actions
>> file+     C:\dev\sfprojects\jobeet\apps\f...s/job\actions/actions.class.php
>> dir+      C:\dev\sfprojects\jobeet\apps\frontend\modules/job\templates
>> file+     C:\dev\sfprojects\jobeet\apps\f...s/job\templates/editSuccess.php
>> file+     C:\dev\sfprojects\jobeet\apps\f.../job\templates/indexSuccess.php
>> file+     C:\dev\sfprojects\jobeet\apps\f...es/job\templates/newSuccess.php
>> file+     C:\dev\sfprojects\jobeet\apps\f...s/job\templates/showSuccess.php
>> file+     C:\dev\sfprojects\jobeet\apps\f...modules/job\templates/_form.php
>> tokens    C:/dev/sfprojects/jobeet/apps/f...s/job/actions/actions.class.php
>> tokens    C:/dev/sfprojects/jobeet/apps/f...s/job/templates/editSuccess.php
>> tokens    C:/dev/sfprojects/jobeet/apps/f.../job/templates/indexSuccess.php
>> tokens    C:/dev/sfprojects/jobeet/apps/f...es/job/templates/newSuccess.php
>> tokens    C:/dev/sfprojects/jobeet/apps/f...s/job/templates/showSuccess.php
>> tokens    C:/dev/sfprojects/jobeet/apps/f...modules/job/templates/_form.php
>> tokens    C:/dev/sfprojects/jobeet/apps/f...s/job/actions/actions.class.php
>> tokens    C:/dev/sfprojects/jobeet/apps/f...s/job/templates/editSuccess.php
>> tokens    C:/dev/sfprojects/jobeet/apps/f.../job/templates/indexSuccess.php
>> tokens    C:/dev/sfprojects/jobeet/apps/f...es/job/templates/newSuccess.php
>> tokens    C:/dev/sfprojects/jobeet/apps/f...s/job/templates/showSuccess.php
>> tokens    C:/dev/sfprojects/jobeet/apps/f...modules/job/templates/_form.php
>> file+     C:\dev\sfprojects\jobeet\test\f...nal\frontend\jobActionsTest.php
>> tokens    C:\dev\sfprojects\jobeet\test\f...nal\frontend\jobActionsTest.php
>> file-     C:/dev/sfprojects/jobeet/cache/...96f/autoJob/templates/_form.php
>> file-     C:/dev/sfprojects/jobeet/cache/...toJob/templates/showSuccess.php
>> file-     C:/dev/sfprojects/jobeet/cache/...utoJob/templates/newSuccess.php
>> file-     C:/dev/sfprojects/jobeet/cache/...oJob/templates/indexSuccess.php
>> file-     C:/dev/sfprojects/jobeet/cache/...toJob/templates/editSuccess.php
>> dir-      C:/dev/sfprojects/jobeet/cache/...db690e723e96f/autoJob/templates
>> file-     C:/dev/sfprojects/jobeet/cache/...toJob/actions/actions.class.php
>> dir-      C:/dev/sfprojects/jobeet/cache/...d7db690e723e96f/autoJob/actions
>> dir-      C:/dev/sfprojects/jobeet/cache/...e90f98f9d7db690e723e96f/autoJob


以上使用了 doctrine:generate-module 來為JobeetJob模型產生 job的前台模組,同時製造了大部分的symfony任務(tasks)、及一些位於 apps\frontend\modules\job\目錄下的檔案及目錄。
actions\ 目錄:The module actions
templates\ 目錄:The module templates

actions\actions.class.php類別:定義了所有job模組的action名稱 / 功能描述,如下:
index : 顯示資料表的所有資料
show : 顯示指定資料的欄位及欄位值
new : 顯示新增資料的表單
create : 產生一筆資料
edit : 顯示編輯資料的表單
update : 根據使用使所送出的值,更新一筆資料
delete : 從資料表刪除一筆指定的資料

可以使用以下的網址,在瀏覽器測試一下job模組:
http://jobeet.localhost/frontend_dev.php/job

2011-10-20

symfony Jobeet學習紀錄--Jobeet專案需求目標(The Project)--(02/24)

Symfony 的練習範例Jobeet : http://www.symfony-project.org/jobeet/1_4/Doctrine/en/
第二天的課程: Day 2: The Project

Jobeet這個專案的目標:建立一個求職網站
  1. Jobeet網站的使用者,有以下四類:
    • admin: He owns the website and has the magic power(網站管理者)
    • user: He visits the website to look for a job(求職者)
    • poster: He visits the website to post a job(張貼求才訊息者)
    • affiliate: He re-publishes some jobs on his website(進階使用者,可以使用Jobeet API)

  2. Jobeet有前台(frontend)與後台(backend)的應用需求
    • frontend前台的需求有七項(F1~F7):提供給使用者使用網站的介面
    • backend後台的需求有三項(B1~B3):提供給管理者管理網站的功能

  3. F1需求:使用者在首頁可以看到最新的求才資料
    當使用者進入Jobeet網站首頁,可以看到最新的求才列表。
    依照工作分類(category)加上發布日期排序,最新發布的在前面。
    工作列表上只顯是工作地點(location)、職位(position)、求才公司(company)
    每一個工作分類,列表中只顯示前十筆工作,並提供該分類中所有工作的連結(F2)
    使用者可以搜尋建立自己的求職工作列表(F3)
    可以張貼一個求才(F5)

  4. F2需求:使用者可以取得所選定分類的求才資料
    當使用者點選工作分類名稱或"more jobs"連結時,他可以看到該分類以日期排序的所有求才工作。
    工作列表以每頁20筆工作,進行分頁。

  5. F3需求:使用者可以用關鍵字,重新搜尋工作列表
    關鍵字搜尋的欄位範圍:工作地點(location)、職位(position)、工作分類(category)、求才公司(company)

  6. F4需求:使用者點選一個工作連結,可以看到這個工作的詳細內容

  7. F5需求:使用者可以張貼求才訊息,求才訊息包含下列資料:
    • Company
    • Type (full-time, part-time, or freelance)
    • Logo (optional)
    • URL (optional)
    • Position
    • Location
    • Category (the user chooses in a list of possible categories)
    • Job description (URLs and emails are automatically linked)
    • How to apply (URLs and emails are automatically linked)
    • Public (whether the job can also be published on affiliate websites)
    • Email (email of the poster)

      張貼求才訊息,不必再特別新增帳號。
      新增求才訊息的作業流程:張貼者填入求才訊息所需的相關資料,預覽檢視求才訊息的正確性。
      張貼者即使沒有Jobeet網站的帳號,也可以使用張貼求才訊息時所給的特殊連結,進行求才資料的修改。
      每則求才訊息可以保留30天(由管理者設定,詳見B2需求),張貼者可以在求才訊息刊登逾期5天內,再刊登30天。

  8. F6需求:使用者可以申請成為可以使用Jobeet API的進階使用者
    一般使用者可以經由認證成為可以使用Jobeet API的近接使用者,要成為進階使用者,必須提供下列資料:
    • Name : 使用者名稱
    • Email : 電子郵件帳號
    • Website URL : 網站的網址

      進階使用者帳號,必須由管理者啟用(B3需求),啟用後進階使用者會收到由電子郵件寄送,使用API的授權
      申請時,進階使用者可以從工作範圍的子範圍中選取工作

  9. F7需求:進階使用者可以經由API瀏覽現有的工作列表
    進階使用者可以使用經授權的API,瀏覽現有的工作列表,取得的瀏覽資料可以使用XML、JSON、YAML等格式,傳送資料。
    進階使用者可以限制傳回的求才筆數,也可以在指定的分類中過濾查詢資料。

  10. B1需求:Jobeet網站由管理者設定
    管理者可以編輯網站上的工作分類

  11. B2需求:Jobeet網站上的求才工作由管理者管理
    管理者可以編輯或移除任何求才工作

  12. B3需求:進階使用者由管理者管理
    管理者可以建立或編輯進階使用者,負責啟用或停用進階使用者
    當管理者啟用一個進階使用者,系統會產生一組唯一的授權給進階使用者使用。
就像其他的網站開發一樣,不會一開始就進入程式碼的編寫,首先必須收集需求並設計系統的模型,這就是上述的準備內容。

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

symfony 1.4.14 開發環境安裝紀錄

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

  2. 建立專案目錄: c:\dev\sfproject
     (目錄名稱路徑上,應避免使用空白,如:My Documents)

  3. 將symfony framework放在 c:\dev\sfproject\lib\vendor目錄下。
    將下載取得的symfony-1.4.14.zip 解壓縮至:c:\dev\sfproject\lib\vendor\ 目錄下。

  4. 建立symfony專案(命名為TestProject):
    切換到 c:\dev\sfproject\ 目錄下,執行以下的命令:
    c:\dev\sfproject>c:\xampp\php\php lib\vendor\symfony\data\bin\symfony generate:project TestProject
  5. 執行以下的命令,測試剛才建立TestProject專案
    c:\dev\sfproject>c:\xampp\php\php lib\vendor\symfony\data\bin\symfony -V
    (-V這個參數會顯示symfony的安裝位置,安裝位置紀錄在C:\dev\sfproject\config\ProjectConfiguration.class.php,檔案中所紀錄的路徑應該是相對位置,不是絕對路徑,這樣在搬移專案目錄時,才不會出問題)
    出現以下訊息,代表TestProject建立成功:
    symfony version 1.4.14 (C:\dev\sfproject\lib\vendor\symfony\lib)

  6. 測試一下,在命令字元下,symfony可以提供哪些功能提示?
    c:\dev\sfproject>c:\xampp\php\php lib\vendor\symfony\data\bin\symfony

  7. 設定資料庫:(使用參數configure:database)
    假設以建立MySQL資料庫sftestdb,可以使用帳號root,密碼password,登入資料庫,建立資料庫設定檔的指令如下:
    c:\dev\sfproject>c:\xampp\php\php lib\vendor\symfony\data\bin\symfony configure:database "mysql:host=localhost;dbname=sftestdb" root password
    資料庫設定檔的存放位置:c:\dev\sfproject\config\database.yml

  8. 建立前台應用程式:(使用參數generate:app參數)
    c:\dev\sfproject>c:\xampp\php\php lib\vendor\symfony\data\bin\symfony generate:app frontend
    (執行上述指令後,會建立以下目錄、檔案)
    >> dir+      C:\dev\sfproject\apps/frontend\config
    >> file+     C:\dev\sfproject\apps/frontend\config/app.yml
    >> file+     C:\dev\sfproject\apps/frontend\...licationConfiguration.class.php
    >> file+     C:\dev\sfproject\apps/frontend\config/cache.yml
    >> file+     C:\dev\sfproject\apps/frontend\config/factories.yml
    >> file+     C:\dev\sfproject\apps/frontend\config/filters.yml
    >> file+     C:\dev\sfproject\apps/frontend\config/routing.yml
    >> file+     C:\dev\sfproject\apps/frontend\config/security.yml
    >> file+     C:\dev\sfproject\apps/frontend\config/settings.yml
    >> file+     C:\dev\sfproject\apps/frontend\config/view.yml
    >> dir+      C:\dev\sfproject\apps/frontend\i18n
    >> dir+      C:\dev\sfproject\apps/frontend\lib
    >> file+     C:\dev\sfproject\apps/frontend\lib/myUser.class.php
    >> dir+      C:\dev\sfproject\apps/frontend\modules
    >> dir+      C:\dev\sfproject\apps/frontend\templates
    >> file+     C:\dev\sfproject\apps/frontend\templates/layout.php
    >> tokens    C:/dev/sfproject/apps/frontend/config/settings.yml
    >> file+     C:\dev\sfproject\web/index.php
    >> file+     C:\dev\sfproject\web/frontend_dev.php
    >> tokens    C:\dev\sfproject\web/index.php
    >> tokens    C:\dev\sfproject\web/frontend_dev.php
    >> rename    C:\dev\sfproject\apps/frontend/...frontendConfiguration.class.php
    >> tokens    C:\dev\sfproject\apps/frontend/...frontendConfiguration.class.php
    >> chmod 777 C:\dev\sfproject\web\uploads
    >> chmod 777 C:\dev\sfproject\cache
    >> chmod 777 C:\dev\sfproject\log
    >> chmod 777 C:\dev\sfproject/symfony
    >> chmod 777 C:/dev/sfproject/web/uploads/assets
    >> dir+      C:\dev\sfproject\test/functional/frontend

  9. 簡化輸入的指令
    在上述的多個指令中,一直在重複輸入c:\xampp\php\php lib\vendor\symfony\data\bin\symfony
    在C:\dev\sfproject\lib\vendor\symfony\data\bin下,有提供一個symfony.bat的批次檔,把這個批次檔複製到C:\dev\sfproject\目錄下,就可以輸入symfony來代替c:\xampp\php\php lib\vendor\symfony\data\bin\symfony
    在symfony.bat這個批次檔中有提到,要建立一個PHP_COMMAND的環境變數,變數的值是php.exe的所在位置,我php.exe的所在位置是:c:\xampp\php\php.exe

  10. 目錄讀取權限的調整
    C:\dev\sfproject\cache  C:\dev\sfproject\log 必須使用完全控制(777)的讀取權限。

  11. Web Server網頁伺服器的設定:
    xampp的apache設定檔位於: c:\xampp\apache\httpd.conf
    將以下內容加到httpd.conf設定檔的最後面:
    NameVirtualHost 127.0.0.1:8080
    Listen 127.0.0.1:8080
    <VirtualHost 127.0.0.1:8080>
        DocumentRoot "c:\dev\sfproject\web"
        DirectoryIndex index.php
        <Directory "c:\dev\sfproject\web">
            AllowOverride All
            Allow from All
        </Directory>
        Alias /sf "c:\dev\sfproject\lib\vendor\symfony\data\web\sf"
        <Directory "c:\dev\sfproject\lib\vendor\symfony\data\web\sf">
            AllowOverride All
            Allow from All
        </Directory>
    </VirtualHost>

    除了使用8080port以外,也可以使用本機自訂的主機名稱,
    在C:\Windows\System32\drivers\etc\目錄下的hosts檔案,加入一行:
    127.0.0.1         testproject.localhost
    並在httpd.conf檔案的最後面,加入以下內容:
    <VirtualHost 127.0.0.1:80>
      ServerName testproject.localhost
      DocumentRoot "c:\dev\sfproject\web"
      DirectoryIndex index.php
      <Directory "c:\dev\sfproject\web">
        AllowOverride All
        Allow from All
      </Directory>
      Alias /sf "c:\dev\sfproject\lib\vendor\symfony\data\web\sf"
      <Directory "c:\dev\sfproject\lib\vendor\symfony\data\web\sf">
        AllowOverride All
        Allow from All
      </Directory>
    </VirtualHost>

  12. 完成了!(httpd.conf有變更,重新啟動Apache)