Здравствуйте!
В самом начале пути к освоению Zend Framework я столкнулся с такой проблемой - при использовании $this->render('header.phtml') выскакивает фатальная ошибка.
Немного обрисую ситуацию:
есть файл начальной загрузки index.php:
CODE ( htmlphp):
скопировать код в буфер обмена
<?php .PATH_SEPARATOR.'./application/models/' include "Zend/Loader.php"; Zend_Loader::loadClass('Zend_Controller_Front'); // setup controller $frontController = Zend_Controller_Front::getInstance(); $frontController->throwExceptions(true); $frontController->setControllerDirectory('./application/controllers'); // run! $frontController->dispatch();
контроллер IndexController.php:
CODE ( htmlphp):
скопировать код в буфер обмена
<?php class IndexController extends Zend_Controller_Action { function init() { $this->view->baseUrl = $this->_request->getBaseUrl(); } function indexAction() { $this->view->title = "My Albums"; echo "<p>in IndexController::indexAction()</p>"; } function addAction() { $this->view->title = "Add New Album"; echo "<p>in IndexController::addAction()</p>"; } function editAction() { $this->view->title = "Edit Album"; echo "<p>in IndexController::editAction()</p>"; } function deleteAction() { $this->view->title = "Delete Album"; echo "<p>in IndexController::deleteAction()</p>"; } }
4 файла видов index.phtml, edit.phtml, add.phtml, delete.phtml:
CODE ( htmlphp):
скопировать код в буфер обмена
<html> <head> <title><?php echo $this->escape($this->title); ?></title> </head> <body> <h1><?php echo $this->escape($this->title); ?></h1> </body> </html>
до этого момента всё работает, но всё меняется, когда я пытаюсь сделать общий хэдер для этих 4 файлов. Вот его код (header.phtml):
CODE ( htmlphp):
скопировать код в буфер обмена
<!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> <link rel="stylesheet" type="text/css" media="screen" href="<?php echo $this->baseUrl;?>/public/styles/site.css" /> </head> <body> <div id="content">
Файлы index.phtml, edit.phtml, add.phtml, delete.phtml тоже изменяю:
CODE ( htmlphp):
скопировать код в буфер обмена
<?php echo $this->render('header.phtml'); ?> <h1> <?php echo $this->escape($this->title); ?> </h1> <?php echo $this->render('footer.phtml'); ?>
В результате высвечивается ошибка:
Цитата:
Fatal error: Uncaught exception 'Zend_View_Exception' with message 'script 'header.phtml' not found in path (./application/views\scripts/)' in C:\Program Files\VertrigoServ\www\zenden\library\Zend\View\Abstract.php:980 Stack trace: #0 C:\Program Files\VertrigoServ\www\zenden\library\Zend\View\Abstract.php(876): Zend_View_Abstract->_script('header.phtml') #1 C:\Program Files\VertrigoServ\www\zenden\application\views\scripts\index\index.phtml(1): Zend_View_Abstract->render('header.phtml') #2 C:\Program Files\VertrigoServ\www\zenden\library\Zend\View.php(108): include('C:\Program File...') #3 C:\Program Files\VertrigoServ\www\zenden\library\Zend\View\Abstract.php(880): Zend_View->_run('./application/v...') #4 C:\Program Files\VertrigoServ\www\zenden\library\Zend\Controller\Action\Helper\ViewRenderer.php(897): Zend_View_Abstract->render('index/index.pht...') #5 C:\Program Files\VertrigoServ\www\zenden\library\Zend\Controller\Action\Helper\ViewRenderer.php(918): Zend_Controller_Action_Helper_ViewRenderer->renderScript('index/i in C:\Program Files\VertrigoServ\www\zenden\library\Zend\View\Abstract.php on line 980
Не подскажете, с чем это может быть связано?
P.S. если в файлах вида поменять $this->render на старый добрый include, всё работает:
CODE ( htmlphp):
скопировать код в буфер обмена
<?php include('header.phtml'); ?> <h1> <?php echo $this->escape($this->title); ?> </h1> <?php include('footer.phtml'); ?>
(Отредактировано автором: 17 Декабря, 2010 - 10:46:58)
|