Zend Framework安裝

===========
1、基本設定:
===========
1. 設定mod_rewrite
編輯httpd.conf
#LoadModule rewrite_module modules/mod_rewrite.so
若是前面的」#」字在的話,就把它拿掉吧
(mod_rewrite的詳細資料,可參考apache網站)
2. 設定include_path
設定include path之目的,是為了方便在include類別時,省去輸入長長一串位置的時間
a) 可直接修改php.ini之設定
b) 或是於程式中動態加入set_include_path
     參考網址:
[url]http://tw2.php.net/set_include_path[/url]
3. 設定httpd.conf之document root
請參考下一段之目錄架構,將document root指向/html
以上設定完之後,請從新啟動Apache,並建議檢視一下error log
看是否有錯誤的地方
==================
2、Zend Framework設定
==================
1.基本目錄架構
|-/application
   |-/controllers (MVC之C)
   |-/models       (MVC之M)
   |-/views         (MVC之V)
     |-/filters
     |-/helpers
     |-/scripts
|-/html
   |-/p_w_picpaths     (存放影像檔案)
   |-/scripts     (存放script檔)
   |-/styles     (存放CSS檔)
   |-.htaccess (配合url rewrite之檔案)
   |-index.php (bootstrap file)
|-/library
   |-/Zend     (這個是ZF的library,可從ZF網站下載)
2. 檔案設定
a)index.php(bootstrap file),可視各別情況修改
<?php
   //Basic Config
   error_reporting(E_ALL | E_STRICT);   //設定Error Report的等級
   date_default_timezone_set('Asia/Taipei');   //設定時區為臺北

   //Include path
   define ('P_S', PATH_SEPARATOR);
   set_include_path('.' .P_S .'../library' .P_S .'../application/models/' .P_S .get_include_path());

   require_once 'Zend/Loader.php';
   Zend_Loader::registerAutoload();

   //Controller
   $frontController = Zend_Controller_Front::getInstance();
   $frontController->setControllerDirectory('../application/controllers');

   $frontController->dispatch();
?>

b).htaccess設定:
RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php

基本上這樣設定完,就差很少把環境建置好了
接下來,就是開始設定各別Controller的工做了
PS1:在windows系統下要作出.htaccess,能夠直接用記事本來作
存檔的時候,選擇「存檔類型(T)」為「全部檔案」,便可直接輸入檔名.htaccess而不會發生錯誤
PS2:其它目錄也可加個.htaccess檔來保護目錄裡的資料
內容為:
deny from all
==============
3、Controller設定
==============
先設定一個最基本的IndexController
架構參閱上一段落
|-/application
   |-/controllers (MVC之C)
     |-
IndexController.php (Index的Controller) <-新增這個
   |-/models       (MVC之M)
   |-/views       (MVC之V)
     |-/filters
     |-/helpers
     |-/scripts
       |-/index   <--新增這個目錄
         |-index.phtml <--新增這個檔案
         |-happy.phtml <--新增這個檔案
a) IndexController.php
<?php
   require_once 'Zend/Controller/Action.php';
   class IndexController extends Zend_Controller_Action{
     public function indexAction(){
       //能夠在寫index的Action
     }

     public function happyAction(){
       //能夠在這裡寫happy的Action
     }
   }
?>

b) index.phtml & happy.phtml這個是indexAction的view,當執行indexAction時,預設會找同名名檔案,並render出頁面內容Controller的設定大概這樣就完成了(細節可再參觀ZF的Document或是其它高手們的Tutorial)接下來,打開browser,輸入網址:[url]http://127.0.0.1/[/url]或是[url]http://127.0.0.1/index[/url]這兩個網址,它都會找IndexController裡index這個action然後會找index.phtml來render頁面內容[url]http://127.0.0.1/index/happy[/url]它則是會找IndexController裡happy這個action然後會找happy.phtml來render頁面內容基本上到這裡,就把這個小小的MVC架構作出來了
相關文章
相關標籤/搜索