Skip to content

Instantly share code, notes, and snippets.

@dz1984
Created January 9, 2014 10:37
Show Gist options
  • Select an option

  • Save dz1984/8332275 to your computer and use it in GitHub Desktop.

Select an option

Save dz1984/8332275 to your computer and use it in GitHub Desktop.
ZendFramework隨手筆記。

為何使用Zend Framework?

Modular

可以與其他應用程式或框架,像堆積木一塊一塊拼湊建置。

Extensible

依照需求簡單改寫。

  • High Performing 設計時考慮到效能調整。

  • Secure 有你所有需要做的加密和安全編碼工具。

  • Community 充滿活力積極的貢獻者和使用者,給幫助和回饋。

  • Enterprise Ready 已經有成功的企業例子。

What new features will I find in Zend Framework 2?

  • An entirely re-written event-driven MVC layer
  • Components practice dependency injection, supported by our Service Locator and DiC components
  • A powerful module management system
  • An EventManager, for writing event-driven systems, as well as for creating cut points in your software for introducing cross-cutting concerns.
  • A new view layer, architected around analyzing the request and generating a suitable response, be it plain old HTML, or Atom feeds or JSON.

簡而言之,

  • PHP 5.3 feaetures such as namespace and closures
  • A modular application architecture
  • Event manager
  • Dependency Injection (DI)

摘要式記錄

  • ZF2的MVC全被包在模組(Module)裡面。
  • ZF模組資料夾結構:
    • config:管理模組設定。
    • src:所有模組程式碼,包含controllers和models。
    • view:存所有模組會用到的views。
  • Module Manager是找Module.php檔案作設定,並呼叫getAutoloaderConfig()getConfig()兩個方法。
  • getAutoloaderConfig()會載入autoload_classmap.php檔案,去include自定覆載的類別,故可在```autoload_classmap.php``新增或刪除Entries來管理自定覆載。
  • getConfig()會載入```config/module.config.php``檔案,去設定模組設定參數,包含routes,controllers,layouts,以及其它設定。
  • ZF2的ServiceManager實作服務分配者design patter,使用service/object分配者去檢索其他物件,分為六大類:
    • abstract_factories:定義抽象類別陣列。
    • aliases:定義alias name/target name關聯陣列。
    • factories:定義service name/factory class name pair陣列。
    • invokables:定義service name/class pair陣列。
    • services:定義service name/object pairs陣列。
    • shared:定義service name/Boolean pair陣列。
  • ServiceManager設定可選擇application或module層級設定。
  • 關鍵factories可放至ServiceManager:
    • Database connections
    • Models and table gateways
    • Form and filters
    • Authentication service
  • TableGateway類別繼承AbstractTableGateway,且實作TableGatewayInterface。
  • TableGatewayInterface提供CRUD介面。
    • getTable()
    • inser($set)
    • select($where = null)
    • update($set,$where=null)
    • delete($where)

Memo how to build a shopping cart

  • Model
    • Create necessary tables.
    • Create necessay table gateway object for data access.
  • Controller
    • indeAction:list all products
    • productDetailAction:display the details of a specific product and allow the user to add a product to the cart.
    • shoppingCartAction:render the shopping cart before leaving for the payment processing page.
    • paypalExpressCheckoutAction: redirect the user to the Paypal Express Checkout page.
    • paymentConfirmAction:handle the redirection from PayPal Express Checkout back to the shopping cart upon sucessful payment.
    • paymentCancelAction:handle the redirection from PayPal Express Checkout back to the shopping cart upon failed payment.
  • View
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment