Zend Framework layout 使用详细教程

我是用zend studio创建的,目录:

3285938878121984385

 

一、index.php 内容:

 

<?php

// Define path to application directory
defined(‘APPLICATION_PATH’)
|| define(‘APPLICATION_PATH’, realpath(dirname(__FILE__) . ‘/../application’));

// Define application environment
defined(‘APPLICATION_ENV’)
|| define(‘APPLICATION_ENV’, (getenv(‘APPLICATION_ENV’) ? getenv(‘APPLICATION_ENV’) : ‘production’));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . ‘/../library’),
get_include_path(),
)));

require_once ‘Zend/Layout.php’;
Zend_Layout::startMvc(array(‘layoutPath’ => APPLICATION_PATH.’/views/layouts’));

/** Zend_Application */
require_once ‘Zend/Application.php’;

// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . ‘/configs/application.ini’
);
$application->bootstrap()
->run();

 

二、IndexController 内容:

 

<?php

class IndexController extends Zend_Controller_Action
{

public function init()
{

$response = $this->getResponse();

$response->insert(‘sidebar’, $this->view->render(‘index/sidebar.phtml’));

}

public function indexAction()
{

$this -> view -> result = ‘123’;

}

}

 

三、index.phtml 内容:

 

<?php echo $this->result; ?>

 

四、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” xml:lang=”en” lang=”en”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>123</title>
</head>
<body>
<div id=”content”>
<?php echo $this->layout()->content ?>
</div>
<div id=”sidebar”>
<?php echo $this->layout()->sidebar; ?>
</div>
</body>
</html>

 

五、sidebar.phtml 内容:

 

Hi, I’m here.

Leave a Reply

Your email address will not be published. Required fields are marked *