PHPEye开源社区 » Zend Framework 使用讨论 » <和Zend Framework一起成长简体中文版>的问题
《Programming PHP》第二版上市
2007-5-31 22:08 kukat
<和Zend Framework一起成长简体中文版>的问题

一开始是按照中文版1.31来做的,出错……
然后直接到作者网站下下载最新的1.34,看的出来这个版本还是给予zf0.92写的。
我完全按照他的指南做,还是出现以下错误

[code]Fatal error: Uncaught exception 'Zend_View_Exception' with message 'script 'header.phtml' not found in path' in D:\wwwroot\zfd\library\Zend\View\Abstract.php:853 Stack trace: #0 D:\wwwroot\zfd\library\Zend\View\Abstract.php(764): Zend_View_Abstract->_script('header.phtml') #1 D:\wwwroot\zfd\application\views\scripts\index\index.phtml(1): Zend_View_Abstract->render('header.phtml') #2 D:\wwwroot\zfd\library\Zend\View.php(46): include('D:\wwwroot\zfd\...') #3 D:\wwwroot\zfd\library\Zend\View\Abstract.php(768): Zend_View->_run('.\application\v...') #4 D:\wwwroot\zfd\library\Zend\Controller\Action.php(214): Zend_View_Abstract->render('index\index.pht...') #5 D:\wwwroot\zfd\application\controllers\IndexController.php(11): Zend_Controller_Action->render() #6 D:\wwwroot\zfd\library\Zend\Controller\Action.php(497): IndexController->indexAction() #7 D:\wwwroot\zfd\library\Zend\Controller\Dispatcher\Standard.php(230): Zend_Controller_Action->dispatch('indexAction') #8 D:\wwwroot\zfd\library\Zend\Controller\Front.php(889): Zend_Contr in D:\wwwroot\zfd\library\Zend\View\Abstract.php on line 853
[/code]

header.phtml是和index.phtml放在application\views\scripts\index下的,不会说找不到此文件……

以下是我的代码
index.php
[code]<?php
error_reporting(E_ALL|E_STRICT);
//date_default_timezone_set('Europe/London');

set_include_path('.' . PATH_SEPARATOR . './library'
        . PATH_SEPARATOR . './application/models/'
        . PATH_SEPARATOR . get_include_path());
include "Zend/Loader.php";

Zend_Loader::loadClass('Zend_Controller_Front');

// setup controller
$frontController = Zend_Controller_Front::getInstance();
$frontController->throwExceptions(true);
$frontController->setControllerDirectory('./application/controllers');
//$frontController->setParam('noViewRenderer',true);                        这句是phpwb开发团队给我说的,但他不起作用。不过还是谢谢这位兄弟
// run!
$frontController->dispatch();[/code]

application/controllers/IndexControllers.php
[code]<?php

class IndexController extends Zend_Controller_Action
{
        function init(){
                $this->initView();
        }
    function indexAction()
    {
        $this->view->title = "My Album";
        $this->render();
    }

    function addAction()
    {
        $this->view->title = "Add Album";
        $this->render();
    }

    function editAction()
    {
        $this->view->title = "Edit Album";
        $this->render();
    }

    function deleteAction()
    {
        $this->view->title = "Delete Album";
        $this->render();
    }
}[/code]

application/views/scripts/index/index.phtml
[code]<?php echo $this->render('header.phtml'); ?>
<h1><?php echo $this->escape($this->title); ?></h1>
<?php echo $this->render('footer.phtml'); ?>[/code]

application/views/scripts/index/header.phtml
[code]<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title><?php echo $this->escape($this->title); ?></title>
</head>
<body>
        <div id="content">[/code]

其他的几个view就不一一列举了

我的环境 xpsp2+php5.21+mysql5.0+zf1.0rc1

[[i] 本帖最后由 kukat 于 2007-5-31 22:12 编辑 [/i]]

2007-5-31 22:36 sxpo
header.phtml 应该在application/views/scripts/目录下

2007-5-31 22:54 Haohappy
sxpo说的应该没错,问题肯定在于路径不对,你也可以把当前执行的路径打印出来看看,到底是在查找哪个目录下的header.phtml。

另外,简单解释一下。0.9.3中ZF可以在controller中直接使用$this->render();来输出模板(只要模板的命名符合默认的要求,比如index.phtml),这个功能是向Ruby on Rails学来的,是契约式开发的一个典型的例子。

phpwb说的:
$frontController->setParam('noViewRenderer',true);  

这一句是用于关闭这种功能的。关闭后你只能像原来那样指定模板文件来输出:

[code]public function viewAction() {
//.....略
$this->view->action = 'view';                                                       
$this->view->actionTemplate = $this->tplDir.'articleView.php';
echo $this->view->render($this->tplDir.'articleMain.php');               
}[/code]

2007-6-1 10:04 kukat
谢谢sxpo 问题的确就是这样
也谢谢Haohappy 感觉zf的view没smarty好……

2007-6-1 10:13 Haohappy
你也可以用Smarty的呵呵。

页: [1]


Powered by Discuz! Archiver 5.5.0  © 2001-2006 Comsenz Inc.