Ubuntu10.10 Zend FrameWork配置及helloworld显示

    技术2022-05-18  15

    、大概思路

    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 、启动运行 (要重启服务器 sudo /etc/init.d/apache2 restart 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.phtm <br /> <br /> <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

    四、总结

    配置环境虽然是件很麻烦的事,但是只要花一些时间,总可以找到相应的解决方法。

    参考网址: http://www.linguofeng.com/2010/10/ubuntu-10-10-configuration-zend-framework.html

    本作品 采用知识共享署名-非商业性使用 2.5 中国大陆许可协议 进行许可。


    最新回复(0)