2010年8月27日 星期五

在FreeBSD 上使用 Zend framework

Zend framework 真的很棒, 使用過後的感想只有棒一個字

寫一下我在FreeBSD 上架設的過程

提供給有需要的人參考

我的環境 

FreeBSD dns.usnei.net 8.0-RELEASE-p4 FreeBSD 8.0-RELEASE-p4

apache-2.2.13       Version 2.2.x of Apache web server with prefork MPM. (聽說worker 會跟php5衝突)


php5-5.3.3_1        PHP Scripting Language

其它應該沒差吧 

apache 修改的部分有  

DirectoryIndex index.php 要記得加入

DocumentRoot "/htdocs"  且針對 /htdocs 的Options FollowSymLinks 要開啟


否則你會在log 觀察到
Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /htdocs/index

針對 apache config httpd.conf 這個檔案僅變動如上所提到 

php5 的部分順便貼一下 

AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .php .php3 .php4 .php5

====================================================================

再來是zend framework  目錄結構  

以我來說, 我已經設定了DocumentRoot 在 /htdocs  

我的目錄結構是這個樣子

/application 
   /models
   /controllers
      ErrorController.php  
      IndexController.php
   /views
     filters/ 
     helpers/ 
     scripts/
        index/ 
             happy.phtml  
             index.phtml
/library 
   Zend                   ->  此為從Zend  下載下來的library 

/htdocs 
      index.php
      .htaccess   

以上提到的目錄及檔案 , 都是手動新增的  以unix like 的 file system 來看應該很清楚

在 ms  上的話, 就以此類推


==============================================================
cat /htdocs/.htaccess 

RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
---------------------------------------------------------------------------------------

cat /htdocs/index.php

  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();
?>
----------------------------------------------------------------------------------------------------------------------
cat  /application/controllers/IndexController.php

  require_once 'Zend/Controller/Action.php';
  class IndexController extends Zend_Controller_Action{
    public function indexAction(){
         $this->view->message = "index 專案裡面的 index 動作"    # 回傳message 供之後利用 
    }
    public function happyAction(){ 
          $this->view->message = "index 專案裡面的 Index Controller 針對 Happy Action 回傳的字串";   #回傳message 同上 
}
  }
?>
---------------------------------------------------------------------------------------
cat /application/controllers/ErrorController.php  

require_once 'Zend/Controller/Action.php';

class ErrorController extends Zend_Controller_Action
{
  public function errorAction()
  {
    die("An error occurred; please try again later.");
  }
}

#假設找不到符合的controller 則秀出 An  error occurred; please try again later  

---------------------------------------------------------------------------------------
cat /application/view/scripts/index/index.phtml 

echo $this->message;
?>

則 http://yourip/index/index 

會秀出  

 index 專案裡面的 index 動作

cat /application/view/scripts/index/happy.phtml 

PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  
  
    這是index專案裡面命名為happy 的view  展現出來的字串
message; ?>

則 http://yourip/index/hapy 

秀出

這是index專案裡面命名為happy 的view  展現出來的字串
index 專案裡面的 Index Controller 針對 Happy Action 回傳的字串

所以要怎麼表現 由 view/script/index/happy.phtml 決定 

而在controller 同樣可以進行某些動作供view 目錄內的 專案目錄/行為.phtml 使用 

先寫到這邊  也許還有些錯誤觀念的地方 

等之後了解更多再慢慢修改 , 若有高手看到錯誤的地方也請指正!

我參考的連結有 


ngoprekweb

網站製作學習誌

感謝以上BLOG 的主人 , 酷學園也是我以前滿愛逛的一個論壇 ~

2010年8月24日 星期二

婚前與婚後

自從小明結婚後, 老婆規定每個月薪水都要繳回家用再領零用錢

小明某天忽然感嘆的跟小華在MSN 上聊到

小明 : e04 , 我今天早上忽然覺得我自己好有錢, 錢包有1千多塊

小華 : ................

小明 : e04 婚前我根本覺得1千多塊不算甚麼錢啊

小華: 你被馴服了 ...

我絕對不會承認我跟小明有任何關連...