成功打印出Hello World!Zend Framework的简单配置!

对应Zend Framework的引导文件的配置,这里命名为index.php,附上代码:

<?php
    //设置环境
    error_reporting(E_ALL|E_STRICT);     //返回当前的错误报告级别
    ini_set('display_errors',true);        //设置把错误信息打印到屏幕
    date_default_timezone_set('Asia/Shanghai');        //设置时区
    
    //设置路径
    $rootDir = dirname(dirname(__FILE__));    //dirname():返回路径中的”目录"部分
    set_include_path($rootDir . '/8030' . '/library' . PATH_SEPARATOR . get_include_path()); 
    /*为当前脚本设置 include_path 运行时的配置选项,也就是路径,相当于系统中的环境变量
      这里 PATH_SEPARATOR 是一个常量,在linux系统中表示" :" ,在windows系统中则表示” ; "
    */
    
    //引入相关文件
    require_once 'Zend/Loader.php';        
    Zend_Loader::loadClass('Zend_Debug');
    Zend_Loader::loadClass('Zend_Controller_Front');
    
    
    //设置控制器
    $frontController = Zend_Controller_Front::getInstance();
    $frontController->setControllerDirectory('./application/controllers');
    //这里setControllerDirectory('./application/controllers')中的路径一定要写正确!!!
    
    //运行
    $frontController->dispatch();
;?>
View Code

总结:路径非常关键,很多次都是因为路径配置的错误而导致Zend Framework不能运行!

使用的目录结构:

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

|---application

|---|---controllers

|---|---|---IndexController.php

|---|---views

|---|---|---scripts

|---|---|---|---index

|---|---|---|---|---index.phtml

|---|---|---helpers

|---|---|---filters

|---|---models

|---library

|---public

|---index.php

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

使用版本:ZendFramework-1.12.3-minimal

附上IndexController.php及其index.phtml代码

<!--IndexController.php-->
<?php
    class IndexController extends Zend_Controller_Action
    {
        public function indexAction()
        {
            $this->view->assign('title','Hello World!');
        }
    }
?>
View Code
<!--index.phtml代码-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" Content="text/html; charset=gbk">
    <title>
        <?php echo $this->escape($this->title);?>
        <!--注意这里escape()的用法-->
    </title>
</head>
<body>
    <h1><?php echo $this->escape($this->title);?></h1>
</body>
</html>
View Code

 

posted @ 2014-02-18 15:15  水煮白干  阅读(237)  评论(0编辑  收藏  举报