ZF学习使用之hello world

ZF 1.11.2

PHP 5.3

创建虚拟站点httpd_vhost.conf

<VirtualHost 192.168.1.106:80>
<Directory "E:/www/zf">
DirectoryIndex index.php
AllowOverride all
Options -Indexes FollowSymLinks
</Directory>
ServerAdmin coderzl@hotmail.com   
DocumentRoot E:/www/zf/public
ServerName zf.zaric.com
ErrorLog "E:/www/logs/zf.localhost-error.log"
CustomLog "E:/www/logs/zf.localhost-access.log" common
</VirtualHost>

/public/.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$  /index.php/$1 [PT,L]

工程目录结构:

image

创建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('Zend/Loader/Autoloader.php');
Zend_Loader ::registerAutoload();

image 

最后一句提示:Zend_Loader::Zend_Loader::registerAutoload is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader,过期用Zend_Loader_Autoloader替代。

下来

Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true);//能够载入无名子空间的类,比如models目录下的类。
$controller = Zend_Controller_Front::getInstance();
$controller->setParam('useDefaultControllerAlways', true);
$controller->setControllerDirectory('../application/controllers/');
$controller->setBaseUrl('../application/controllers/');
$controller->dispatch();

建立:/application/controllers/IndexController.php

class IndexController extends Zend_Controller_Action
{
    function indexAction(){}

    function doAction(){}
}

同时建立:/application/views/script/index/index.phtml

否则会报出异常:Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)

最后运行:http://zf.zaric.com/index/index

image

http://zf.zaric.com/index/do

image

done!~

posted @ 2011-02-17 17:32  zaric  阅读(614)  评论(0编辑  收藏  举报