一.Create YourProject
詳細請看這篇文章:
http://blog.csdn.net/u012675743/article/details/45511019
二.The BootStrap
Bootstrap用來定義你的項目資源和組件初始化。類如下:
//application/Bootstrap.php class Bootstrapextends Zend_Application_Bootstrap_Bootstrap{}
詳細還可以參考這篇文章:
http://blog.csdn.net/u012675743/article/details/45510903
三.Configuration
經常需要自己配置應用,預設設定檔在application/configs/application.ini,
其中也包含了指令用來設定PHP環境,聲明bootstrap路徑,
; application/configs/application.ini[production]phpSettings.display_startup_errors = 0phpSettings.display_errors = 0includePaths.library = APPLICATION_PATH "/../library"bootstrap.path = APPLICATION_PATH "/Bootstrap.php"bootstrap.class = "Bootstrap"resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"[staging : production][testing : production]phpSettings.display_startup_errors = 1phpSettings.display_errors = 1[development : production]phpSettings.display_startup_errors = 1phpSettings.display_errors = 1
四.Action Controllers
一個controller應該有一個或者多個methods,這些methods可以通過瀏覽器被請求。通常可以寫一個indexcontroller,作為網站的首頁。
預設的indexcontroller為下:
// application/controllers/IndexController.phpclass IndexController extends Zend_Controller_Action{ public function init() { /* Initialize action controller here */ } public function indexAction() { // action body }}
五.Views
每個controller都在application/views/scripts/下有一個對應的視圖。並相應的命名為 ‘controller/controller.phtml’,主要寫前台要展示的頁面。
六.Create A Layout
在命令列下輸入:
記得一定要切換到工程檔案夾下,否則會出現如下提示:
然後開啟layouts檔案夾下,會出現一個scripts檔案夾。
七. Create a Model andDatabase Table
對資料庫中要操作的每一個表都需要寫一個表類,$_primary為表的主鍵,例如:
八. Create A Form
使用架構的form來提交資料的入口是非常方便的。在application下建立目錄forms,即application/forms,並建立相應的form class。
例如:
setMethod('post'); // Add an email element $this->addElement('text', 'email', array( 'label' => 'Your emailaddress:', 'required' => true, 'filters' =>array('StringTrim'), 'validators' => array( 'EmailAddress', ) )); // Add the comment element $this->addElement('textarea', 'comment', array( 'label' => 'PleaseComment:', 'required' => true, 'validators' => array( array('validator' =>'StringLength', 'options' => array(0, 20)) ) )); // Add a captcha $this->addElement('captcha', 'captcha', array( 'label' => 'Please enterthe 5 letters displayed below:', 'required' => true, 'captcha' => array( 'captcha' => 'Figlet', 'wordLen' => 5, 'timeout' => 300 ) )); // Add the submit button $this->addElement('submit', 'submit', array( 'ignore' => true, 'label' => 'Sign Guestbook', )); // And finally add some CSRF protection $this->addElement('hash', 'csrf', array( 'ignore' => true, )); }}
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。
以上就介紹了Zend Framework 入門,包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。