SlideShare ist ein Scribd-Unternehmen logo
1 von 39
Downloaden Sie, um offline zu lesen
Symfony 簡介
Who am I

    Ricky 是我
   http://ricky.ez2.us/
   ricky@ez2.us
   http://www.plurk.com/rickysu
Symfony
a web application framework
      for PHP projects
Version 1.0
released early 2007
 under MIT license.

    sponsored by Sensio
Symfony 整合了這些東西
   Mojavi3­DEV  ­  Controller
   Propel , Doctrine  ­   ORM
   Prado  ­  for i18n support
   Spyc  ­  for YAML Parsing
   Pake  ­  for command­line tool 
Symfony 也參考了其他 Framework
   Ruby 
     ­ Rails :  Helpers for templates, routing.
   Java
      ­ Spring : Dependency injection container.
   Python
     ­ Django : request / response , controller
Symfony 也創造了一些新東西
   Web debug toolbar 。
   新的 Form  元件,取代 helper 系統。
但這都不是重點
如何使用 Symfony !
開發工具 ?
選 Netbeans 就對了

http://netbeans.org/
Netbeans Demo
The Routing
# apps/frontend/config/routing.yml
member: 
  url:          /:module.aspx
  param:    { action: index }
member_actions_edit:
  url:         /:module/:id­:name.html
  param:  { action: edit }
  options: 
     segment_separators:    [ '/' , '­' , '.' ]
  requirements:
     id:    'd+'
member_actions:
  url:         /:module/:id/:action
  requirements:
     id:    'd+'
The Forms

  Widgets           Validator


用來決定欄位的型態     用來驗證欄位數值
以往採用 helper 的產生方式
<?php echo form_tag('Regist',array('method'=>'POST'))?>
<tr>
   <td><?php echo label_tag($form['name'])?></td>
    <td><?php echo input_tag($form['name'])?></td>
</tr>
<tr>
   <td><?php echo label_tag($form['sex'])?></td>
    <td><?php echo radio_button_tag($form['sex'])?></td>
</tr>
<?php echo form_tag_end()?>
新的 Form Object
   表單欄位型態在 form object 中定義。
   表單數值在 form object 中檢查。
   將表單的驗證邏輯由 controller 中抽離。
   讓表單可以重用。
Form in template(view)
<?php echo form_tag('Regist',array('method'=>'POST'))?>
  <?php echo $Form­>renderHiddenFields() ?>
  <?php foreach($Form as $FormField):?>
  <?php if(!$FormField­>isHidden()):?>
    <div>
      <?php echo $FormField­>renderLabel()?>
      <?php echo $FormField?>
      <?php if($FormField­>hasError()):?>
         <span><?php echo $FormField­>renderError()?></span>
      <?php endif?>
   </div>
  <?php endif?>
  <?php endforeach?>
<?php echo form_tag_end()?>
Form in action(controller)
    public function executeRegist(sfWebRequest $Request){
        $this­>Form = new RegisterForm(new Register());
        if($Request­>isMethod('post')){
             $this­>Form­>bind(
                   $Request­>getParameter($this­>Form­>getName())
             );
             if($this­>Form­>isValid()) {
                   $this­>Form­>save();
             }
        }
    }
i18n
   Symfony 提供了多國語言的支援。
   幾個步驟就輕鬆搞定。
Admin Generator
   這是一個快速後台產生器。
   有用過 Ruby on Rails  或是 Django 的人一
     定不陌生。
   只需修改 config 就可以作一個具有權限控
     管的後台了。
Web Debug Toolbar
Why Symfony?
文件多
    http://www.symfony­project.org/doc/1_4/
   A Gentle Introduction to symfony
   Practical symfony
   The symfony Reference Book
   More with symfony
活躍的社群
   Mailing­list / forum / IRC
   More than 1300 plugins , 500 developers.
   300K unique visitors per month 
     on the official web site 
     http://www.symfony­project.org/
多到不行的 Config
Symfony 預設情況下
不修改 Config 就能運作
但是 Config 可以作很多事
cache.yml              security.yml
_list:                 all:
   enabled:  true         is_secure:   true
   lifetime:  3600        credentials: admin
index:                 edit:
  enabled:  true         credentials: [admin,edit]
  lifetime:  3600
  with_layout: false
Symfony 被批評的地方
安裝麻煩 ?
安裝方法
   安裝 Symfony core lib
     pear channel­discover pear.symfony­project.com
     pear install symfony/symfony


   建立專案
     symfony generate:project myproject

沒有解開壓縮檔的步驟,這果然很麻煩。
設定 db schema 好麻煩
從已存在的 DB 中建立 Model
   在 DB 宣告好 foreign key 。
   匯入 schema.yml
     symfony docteint:build­schema
   建立 model , form , filters
     symfony doctrine:build –all­classes

    不用宣告 has_many , belongs_to 。
    Table 名稱不用是複數,這好麻煩。
Symfony 效能太差 ?
其實是有解決方法的
請不要用 Symfony

die('Hello World');
Symfony 已經足夠應付許多大型專案
   Yahoo! Answers
   Yahoo! Bookmarks
   delicious.com
還有疑慮嗎 ?
24 天的實戰教程
         幫你解除疑惑。
http://www.symfony-project.org/jobeet/1_4/Doctrine/en/
Thanks

Weitere ähnliche Inhalte

Andere mochten auch

Hedge Funds: Trends and Insight From the Industry and Investors
Hedge Funds: Trends and Insight From the Industry and InvestorsHedge Funds: Trends and Insight From the Industry and Investors
Hedge Funds: Trends and Insight From the Industry and Investors
ManagedFunds
 
Bedrijfspresentatie Trimension
Bedrijfspresentatie TrimensionBedrijfspresentatie Trimension
Bedrijfspresentatie Trimension
mhuibers
 
Kate Stephens - Slides
Kate Stephens - SlidesKate Stephens - Slides
Kate Stephens - Slides
Kate Stephens
 
4. list of figure
4. list of figure4. list of figure
4. list of figure
Izzah Noah
 
Officejet 100 mobile printer
Officejet 100 mobile printerOfficejet 100 mobile printer
Officejet 100 mobile printer
R. T. Creager
 
Sales Assist Group Presentation
Sales Assist Group PresentationSales Assist Group Presentation
Sales Assist Group Presentation
Veno30472 Veno
 

Andere mochten auch (20)

The Game as Design Principle
The Game as Design PrincipleThe Game as Design Principle
The Game as Design Principle
 
resume draft sheet
resume draft sheetresume draft sheet
resume draft sheet
 
Hedge Funds: Trends and Insight From the Industry and Investors
Hedge Funds: Trends and Insight From the Industry and InvestorsHedge Funds: Trends and Insight From the Industry and Investors
Hedge Funds: Trends and Insight From the Industry and Investors
 
2014: The Year Ahead for Hedge Funds
2014: The Year Ahead for Hedge Funds2014: The Year Ahead for Hedge Funds
2014: The Year Ahead for Hedge Funds
 
Assessment 2
Assessment 2Assessment 2
Assessment 2
 
Bedrijfspresentatie Trimension
Bedrijfspresentatie TrimensionBedrijfspresentatie Trimension
Bedrijfspresentatie Trimension
 
Kate Stephens - Slides
Kate Stephens - SlidesKate Stephens - Slides
Kate Stephens - Slides
 
4. list of figure
4. list of figure4. list of figure
4. list of figure
 
Research Paper by Dr Everett Ehrlich
Research Paper by Dr Everett EhrlichResearch Paper by Dr Everett Ehrlich
Research Paper by Dr Everett Ehrlich
 
How Passage of the JOBS Act Impacts Regulation D: Private Placement and Gene...
How Passage of the JOBS Act Impacts Regulation D:  Private Placement and Gene...How Passage of the JOBS Act Impacts Regulation D:  Private Placement and Gene...
How Passage of the JOBS Act Impacts Regulation D: Private Placement and Gene...
 
The marketing environment
The marketing environmentThe marketing environment
The marketing environment
 
T-Rex
T-RexT-Rex
T-Rex
 
Officejet 100 mobile printer
Officejet 100 mobile printerOfficejet 100 mobile printer
Officejet 100 mobile printer
 
My Passion
My PassionMy Passion
My Passion
 
Security Enhancements in Windows Server 2012 Securing the Private - Cloud Inf...
Security Enhancements in Windows Server 2012Securing the Private - Cloud Inf...Security Enhancements in Windows Server 2012Securing the Private - Cloud Inf...
Security Enhancements in Windows Server 2012 Securing the Private - Cloud Inf...
 
Sales Assist Group Presentation
Sales Assist Group PresentationSales Assist Group Presentation
Sales Assist Group Presentation
 
LAB1:Adherence
LAB1:AdherenceLAB1:Adherence
LAB1:Adherence
 
The art of seo
The art of seoThe art of seo
The art of seo
 
From their Perspective
From their PerspectiveFrom their Perspective
From their Perspective
 
FP Horak Wedding Presentation
FP Horak Wedding Presentation FP Horak Wedding Presentation
FP Horak Wedding Presentation
 

Ähnlich wie Symfony簡介

Phalcon the fastest php framework 阿土伯
Phalcon   the fastest php framework 阿土伯Phalcon   the fastest php framework 阿土伯
Phalcon the fastest php framework 阿土伯
Hash Lin
 
OpenWebSchool - 11 - CodeIgniter
OpenWebSchool - 11 - CodeIgniterOpenWebSchool - 11 - CodeIgniter
OpenWebSchool - 11 - CodeIgniter
Hung-yu Lin
 
Openshift by mtchang
Openshift by mtchangOpenshift by mtchang
Openshift by mtchang
Chang Mt
 
Spring 2.x 中文
Spring 2.x 中文Spring 2.x 中文
Spring 2.x 中文
Guo Albert
 
跟我一起學 CakePHP
跟我一起學 CakePHP跟我一起學 CakePHP
跟我一起學 CakePHP
Ray Wei
 

Ähnlich wie Symfony簡介 (20)

HTML+COIMOTION 開發跨平台 app
HTML+COIMOTION 開發跨平台 appHTML+COIMOTION 開發跨平台 app
HTML+COIMOTION 開發跨平台 app
 
大话Php之性能
大话Php之性能大话Php之性能
大话Php之性能
 
Admin generator
Admin generatorAdmin generator
Admin generator
 
Phalcon the fastest php framework 阿土伯
Phalcon   the fastest php framework 阿土伯Phalcon   the fastest php framework 阿土伯
Phalcon the fastest php framework 阿土伯
 
Phalcon phpconftw2012
Phalcon phpconftw2012Phalcon phpconftw2012
Phalcon phpconftw2012
 
张所勇:前端开发工具推荐
张所勇:前端开发工具推荐张所勇:前端开发工具推荐
张所勇:前端开发工具推荐
 
OpenWebSchool - 11 - CodeIgniter
OpenWebSchool - 11 - CodeIgniterOpenWebSchool - 11 - CodeIgniter
OpenWebSchool - 11 - CodeIgniter
 
Uliweb cheat sheet_0.1
Uliweb cheat sheet_0.1Uliweb cheat sheet_0.1
Uliweb cheat sheet_0.1
 
程式人雜誌 -- 2015 年5月號
程式人雜誌 -- 2015 年5月號程式人雜誌 -- 2015 年5月號
程式人雜誌 -- 2015 年5月號
 
程式人雜誌 2015年五月
程式人雜誌 2015年五月程式人雜誌 2015年五月
程式人雜誌 2015年五月
 
Openshift by mtchang
Openshift by mtchangOpenshift by mtchang
Openshift by mtchang
 
Spring 2.x 中文
Spring 2.x 中文Spring 2.x 中文
Spring 2.x 中文
 
Mojito 開發 mobile web 實戰經驗談
Mojito 開發 mobile web 實戰經驗談Mojito 開發 mobile web 實戰經驗談
Mojito 開發 mobile web 實戰經驗談
 
Introduction to MVC of CodeIgniter 2.1.x
Introduction to MVC of CodeIgniter 2.1.xIntroduction to MVC of CodeIgniter 2.1.x
Introduction to MVC of CodeIgniter 2.1.x
 
Cfengine培训文档 刘天斯
Cfengine培训文档 刘天斯Cfengine培训文档 刘天斯
Cfengine培训文档 刘天斯
 
Php调试技术手册发布(1.0.0 pdf)
Php调试技术手册发布(1.0.0 pdf)Php调试技术手册发布(1.0.0 pdf)
Php调试技术手册发布(1.0.0 pdf)
 
跟我一起學 CakePHP
跟我一起學 CakePHP跟我一起學 CakePHP
跟我一起學 CakePHP
 
基于Symfony框架下的快速企业级应用开发
基于Symfony框架下的快速企业级应用开发基于Symfony框架下的快速企业级应用开发
基于Symfony框架下的快速企业级应用开发
 
CodeIgniter 2.0.X
CodeIgniter 2.0.XCodeIgniter 2.0.X
CodeIgniter 2.0.X
 
Mopcon2014 - 使用 Sinatra 結合 Ruby on Rails 輕鬆打造完整 Full Stack 網站加 API Service服務
Mopcon2014 - 使用 Sinatra 結合 Ruby on Rails 輕鬆打造完整 Full Stack 網站加 API Service服務Mopcon2014 - 使用 Sinatra 結合 Ruby on Rails 輕鬆打造完整 Full Stack 網站加 API Service服務
Mopcon2014 - 使用 Sinatra 結合 Ruby on Rails 輕鬆打造完整 Full Stack 網站加 API Service服務
 

Symfony簡介