一、大概思路
1.1、
(備注:安裝Zend Framework,其附帶apache2和php5)
1.2、
二、Zend Framework配置
2.1、安裝Zend Framework
在ubuntu10.10的軟件中心安裝zf.
2.2、激活apache的rewrite模塊
命令行輸入:sudo a2enmod rewrite
2.3、配置PHP5路徑
配置include_path路徑信息,修改/etc/php5/con.d目錄下的zend-framework.ini
終端輸入:sudo gedit /etc/php5/conf.d/zend-framework.ini
2.4、創建firstProject項目
終端輸入:zf create project firstProject
(其路徑默認為 Ubuntu主文件目錄下)
2.5、在Apache2建立firstProject項目配置文件
因為apache默認的web目錄是在/var/www下,為了能夠讓 apache自動定位到指定目錄下的web應用,這里我們在/etc/apache2/conf.d中創建一個關于firstProject的配置文件,稱為 firstProject.conf。
終端輸入:sudo gedit /etc/apache2/conf.d/firstProject.conf
文件的內容是:
<IfModule alias_module>
Alias /firstProject "/home/administrator/firstProject/public/"
<Directory "/home/administrator/firstProject/public/">
Allow from all
RewriteEngine on
RewriteBase /firstProject
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !/.(css|js|jpg|gif|png|swf|flv)$ index.php
Options FollowSymlinks MultiViews
AllowOverride All
</Directory>
</IfModule>
2.6、修改項目firstProject的public文件下的.htaccess
增加一行RewriteBase /firstProject
(.htaccess默認是隱藏的,可按快捷鍵Ctrl+H顯示出來)
RewriteEngine On
RewriteBase /firstProject
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
2.7、啟動運行http://localhost/firstProject
三、Zend Framework顯示hello
3.1、從終端進入firstProject文件夾內,運行zf create Controller showhello
3.2、編寫application/controllers/ShowhelloController.php
<?php
class ShowhelloController extends Zend_Controller_Action {
public function init() {
/* Initialize action controller here */
}
public function indexAction() {
// action body
$this->view->content = "Hello World";
$this->render ();
}
}
3.3、編寫application/views/scripts/showhello/index.phtml
<center>View script for controller <b>Showhello </b> and script/action
name <b>index</b>
<p><font color="#FF0000">
<?=$this->content;?>
</font></p>
</center>
3.4、運行http://localhost/firstProject/showhello
四、總結
配置環境雖然是件很麻煩的事,但是只要花一些時間,總可以找到相應的解決方法。
新聞熱點
疑難解答