【问题标题】:Unable to see layout homepage in Zend MVC在 Zend MVC 中看不到布局主页
【发布时间】: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


【解决方案1】:

您不会在 layout.phtml 中回显您的 $this-&gt;layout()-&gt;content; 段。试试看。

编辑:我看到你也没有回应你的 doctype()。就核心 ZF 而言,什么都没有被打印出来,但返回。这样,可以选择如何处理该值(打印、返回、存储、缓存、丢弃等)。我会给你的倾向起个名字:“wordpress 期望”。

【讨论】:

    猜你喜欢
    • 2021-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-06
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    相关资源
    最近更新 更多