【发布时间】:2015-08-11 21:06:20
【问题描述】:
当我在 bootstrap.php 中添加这段代码时
Zend_Layout::startMvc(APPLICATION_PATH . '/layouts/scripts');
$view = Zend_Layout::getMvcInstance()->getView();
unset($view);
为什么不在我的主页显示“hello world”?
应用程序/视图/脚本/index/index.phtml
<p> Hello World </p>
应用程序/布局/脚本/layout.phtml
<?php $this->doctype();?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<?php $this->layout()->content; ?>
</body>
</html>
public/index.php
<?php
error_reporting(E_ALL || E_STRICT);
// Identify the location of the application directory in respect to
// the bootstrap file's location, and configure PHP's include_path to
// include the library directory's location
define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application/'));
set_include_path(
APPLICATION_PATH . '/../library'. PATH_SEPARATOR . get_include_path()
);
// Give the Zend Framework the ability to load classes on demand,
// as you request them, rather than having to deal with require() statements.
require_once "Zend/Loader.php";
Zend_Loader::registerAutoload();
// Retrieve the bootstrap.php file
try {
require '../application/bootstrap.php';
} catch (Exception $exception) {
printf("Could not locate bootstrap.php");
exit(1);
}
// Start using the front controller in order to route URL requests
Zend_Controller_Front::getInstance()->dispatch();
应用程序/bootstrap.php
<?php
// Configure the site environment status.
defined('APPLICATION_ENVIRONMENT')
or define('APPLICATION_ENVIRONMENT', 'development');
// Invoke the front controller
$frontController = Zend_Controller_Front::getInstance();
// Identify the location of the controller directory
$frontController->setControllerDirectory(APPLICATION_PATH . '/controllers');
// Create the env parameter so you can later access the environment
// status within the application.
$frontController->setParam('env', APPLICATION_ENVIRONMENT);
// view and layout setup
// Layout Configuration
Zend_Layout::startMvc(APPLICATION_PATH . '/layouts/scripts');
$view = Zend_Layout::getMvcInstance()->getView();
unset($view);
// $view->headTitle()->setSeparator(' - ');
// $view->headMeta()->appendHttpEquiv('Content-Language', 'en-US');
// Clean up allocated script resources
unset($frontController);
公共/.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
【问题讨论】:
-
您的实际问题是什么?
-
您在主页上看到了什么?
-
它是空的。我的页面是白色的。当我查看源代码时有 html 标签但 / 不包括 Hello World
标签: php zend-framework bootstrapping