Zend Framework 入門

來源:互聯網
上載者:User
一.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教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.