Zend framework Zend框架-视图不';行不通

Zend framework Zend框架-视图不';行不通,zend-framework,view,render,Zend Framework,View,Render,我正在用Zend制作我的第一个应用程序,我遇到了一个问题 zfttutorial.dev\application\controllers\IndexController.php <?php class IndexController extends Zend_Controller_Action { public function init() { /* Initialize action controller here */ } public

我正在用Zend制作我的第一个应用程序,我遇到了一个问题

zfttutorial.dev\application\controllers\IndexController.php

<?php
class IndexController extends Zend_Controller_Action
{
    public function init()
    {
        /* Initialize action controller here */
    }
    public function indexAction()
    {
        $this->view->title = "My Albums"; 
    }
}

zf教程/application/views/scripts/header.phtml

<?php echo $this->render('header.phtml'); ?>
<h1><?php echo $this->escape($this->title); ?></h1>
<?php echo $this->render('footer.phtml'); ?>
<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">
      </div>
   </body>
</html>
<h1><?php echo $this->escape($this->title); ?></h1>
<html>
<head>
<?php echo $this -> headTitle(); //get the title ?>
</head>
<body>
<?php echo $this->render('header.phtml'); //relative to layouts/scripts ?>
<?php echo $this->layout()->content; //the view script redered in the controller action?>
<?php echo $this->render('footer.phtml'); //relative to layouts/scripts ?>
</body>
<?php echo $this->partial('header.phtml', array('title' => $this->title)); ?>
<h1><?php echo $this->escape($this->title); ?></h1>
<?php echo $this->partial('footer.phtml'); ?>

zf教程/application/views/scripts/footer.phtml

<?php echo $this->render('header.phtml'); ?>
<h1><?php echo $this->escape($this->title); ?></h1>
<?php echo $this->render('footer.phtml'); ?>
<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">
      </div>
   </body>
</html>
<h1><?php echo $this->escape($this->title); ?></h1>
<html>
<head>
<?php echo $this -> headTitle(); //get the title ?>
</head>
<body>
<?php echo $this->render('header.phtml'); //relative to layouts/scripts ?>
<?php echo $this->layout()->content; //the view script redered in the controller action?>
<?php echo $this->render('footer.phtml'); //relative to layouts/scripts ?>
</body>
<?php echo $this->partial('header.phtml', array('title' => $this->title)); ?>
<h1><?php echo $this->escape($this->title); ?></h1>
<?php echo $this->partial('footer.phtml'); ?>

但当我去地址

我在浏览器中获得以下信息:

发生错误

应用程序错误

当然,我设置了vhosts文件,当我使用

zfttutorial.dev/application/views/scripts/index/index.phtml

<?php echo $this->render('header.phtml'); ?>
<h1><?php echo $this->escape($this->title); ?></h1>
<?php echo $this->render('footer.phtml'); ?>
<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">
      </div>
   </body>
</html>
<h1><?php echo $this->escape($this->title); ?></h1>
<html>
<head>
<?php echo $this -> headTitle(); //get the title ?>
</head>
<body>
<?php echo $this->render('header.phtml'); //relative to layouts/scripts ?>
<?php echo $this->layout()->content; //the view script redered in the controller action?>
<?php echo $this->render('footer.phtml'); //relative to layouts/scripts ?>
</body>
<?php echo $this->partial('header.phtml', array('title' => $this->title)); ?>
<h1><?php echo $this->escape($this->title); ?></h1>
<?php echo $this->partial('footer.phtml'); ?>


那么一切都好了。问题是这
和这
行在哪里,但我不知道是怎么回事。

您的视图似乎没有向ZF注册。尝试通过在引导类中放置以下方法来注册它们

   public function _initViewScripts(){
         $this->bootstrap ( 'view' );
         $view = $this->getResource('view');
         //Replace layout/scripts with the folder which contains your header.phtml and footer.phtml
         $view->addScriptPath (APPLICATION_PATH. '/layouts/scripts/');
   }
另外,如果您已将页眉和页脚视图放置在
/application/views/scripts/index/
目录中,请将它们移动到更高的目录,如
/layouts/scripts/
尝试以下操作:

在文件夹layouts/scripts/中创建header.phpfooter.php

然后在布局.phtml中呈现页眉和页脚脚本

layout.phtml

<?php echo $this->render('header.phtml'); ?>
<h1><?php echo $this->escape($this->title); ?></h1>
<?php echo $this->render('footer.phtml'); ?>
<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">
      </div>
   </body>
</html>
<h1><?php echo $this->escape($this->title); ?></h1>
<html>
<head>
<?php echo $this -> headTitle(); //get the title ?>
</head>
<body>
<?php echo $this->render('header.phtml'); //relative to layouts/scripts ?>
<?php echo $this->layout()->content; //the view script redered in the controller action?>
<?php echo $this->render('footer.phtml'); //relative to layouts/scripts ?>
</body>
<?php echo $this->partial('header.phtml', array('title' => $this->title)); ?>
<h1><?php echo $this->escape($this->title); ?></h1>
<?php echo $this->partial('footer.phtml'); ?>
MyController.php

<?php
class IndexController extends Zend_Controller_Action
{
    public function init()
    {
        /* Initialize action controller here */
    }
    public function indexAction()
    {
        $this->view->title = "My Albums"; 
    }
}
控制器操作init()函数中,添加以下行:

//Prepended - My Domain
$this->view->headTitle()->prepend('Prepended');

//My Domain - Appended
$this->view->headTitle()->append('Appended');

我认为使用布局是更好的解决方案

但使用您的代码,您可以做到这一点:
在zfttutorial.dev/application/views/scripts/index/index.phtml中

<?php echo $this->render('header.phtml'); ?>
<h1><?php echo $this->escape($this->title); ?></h1>
<?php echo $this->render('footer.phtml'); ?>
<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">
      </div>
   </body>
</html>
<h1><?php echo $this->escape($this->title); ?></h1>
<html>
<head>
<?php echo $this -> headTitle(); //get the title ?>
</head>
<body>
<?php echo $this->render('header.phtml'); //relative to layouts/scripts ?>
<?php echo $this->layout()->content; //the view script redered in the controller action?>
<?php echo $this->render('footer.phtml'); //relative to layouts/scripts ?>
</body>
<?php echo $this->partial('header.phtml', array('title' => $this->title)); ?>
<h1><?php echo $this->escape($this->title); ?></h1>
<?php echo $this->partial('footer.phtml'); ?>

header.phtml和footer.phtml在项目中存储在哪里?