2008-4-17 22:49
atoat
Zend_Layout不显示的问题
我的目录如下附件的图.
我用Zend_Layout组件,但是只是把侧边(sidebar.phtml)那个模板显示出来了.主内容(index.phtml)没有显示,还有标题($this->title)虽然也赋值了可是也没有显示,不知道为什么.请高手帮我看看是哪面错了.
附件是源码和我的目录设置图.
源文件:
index.php
复制PHP内容到剪贴板PHP代码:
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors',1);
date_default_timezone_set('PRC');
// directory setup and class loading
set_include_path('.' . PATH_SEPARATOR . '../library/' . PATH_SEPARATOR . '../application/models' . PATH_SEPARATOR . get_include_path());
include "Zend/Loader.php";
Zend_Loader::registerAutoload();
// load configuration
$config = new Zend_Config_Ini('../application/config.ini','general');
$registry = Zend_Registry::getInstance();
$registry->set('config',$config);
// setup database
$db = Zend_Db::factory($config->db);
Zend_Db_Table::setDefaultAdapter($db);
// setup view
$view = new Zend_view();
$view->setScriptPath('../application/views');
$registry->set('view',$view);
// setup controller
$frontController = Zend_Controller_Front::getInstance();
$frontController->throwExceptions(true);
$frontController->setParams(array('noViewRenderer'=>true));
$frontController->setControllerDirectory('../application/controllers');
Zend_Layout::startMvc(array('layoutPath'=>'../application/layouts'));
// run!
$frontController->dispatch();
IndexController.php
复制PHP内容到剪贴板PHP代码:
class IndexController extends Zend_Controller_Action
{
public $view;
public function init()
{
$this->view = Zend_Registry::get('view');
$response = $this->getResponse();
$response->insert('sidebar',$this->view->render('sidebar.phtml'));
}
public function indexAction()
{
$this->view->title = 'My Albums';
}
public function addAction()
{
$this->view->title = 'Add New Album';
}
public function editAction()
{
$this->view->title = 'Edit Album';
}
public function deleteAction()
{
$this->view->title = 'Delete Album';
}
}
layout.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" c />
<title><?php echo $this->escape($this->title);?></title>
</head>
<body>
<?php echo $this->layout()->sidebar;?>
<?php echo $this->layout()->content;?>
</body>
</html>
[[i] 本帖最后由 atoat 于 2008-4-17 22:51 编辑 [/i]]