SiteCake和我的PHP发生了冲突

时间:2014-02-11 16:01:17

标签: php

我正在尝试安装sitecake,我按照所有说明操作,在页面顶部添加<?php include "sitecake/server/sitecake_entry.php"; ?>,并将类添加到我想要编辑的div中。

问题是,当我添加<?php include "sitecake/server/sitecake_entry.php"; ?>我的PHP停止工作时,为什么会这样?我做错了什么?

例如,以下是我使用PHP添加到页面中的一个PHP脚本:

<!--add class .active to current page-->
<?php
   $directoryURL = $_SERVER['REQUEST_URI'];
   $path = parse_url($directoryURL, PHP_URL_PATH);
   $components = explode('/', $path);
   $currentPage = preg_replace("/\\.[^.\\s]{3,4}$/", "", end($components));

   if ($currentPage == "") {
      $currentPage = "index";
   }

   function href($url) {
      global $currentPage;
      $path = explode('/', $url);
      $page = preg_replace("/\\.[^.\\s]{3,4}$/", "", end($path));
      echo 'href="' . $url . '" ';

      if ($page == $currentPage) {
         echo 'class="active"';
      }
   }
?>

这是我使用error_reporting(E_ALL)时得到的错误:

Fatal error: Uncaught exception 'Zend_Session_Exception'
  with message 'Session must be started before any output has been sent to the browser; output started in /home/approach/public_html/index.php/2'
  in /home/approach/public_html/sitecake/server/library/Zend/Session.php:454

Stack trace:
#0 /home/approach/public_html/sitecake/server/library/Zend/Session/Namespace.php(143): Zend_Session::start(true)
#1 /home/approach/public_html/sitecake/server/application/services/impl/onesite/Bootstrap.php(21): Zend_Session_Namespace->__construct('Default', false)
#2 /home/approach/public_html/sitecake/server/library/Zend/Application/Bootstrap/BootstrapAbstract.php(666): Bootstrap->_initSession()
#3 /home/approach/public_html/sitecake/server/library/Zend/Application/Bootstrap/BootstrapAbstract.php(619): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('session')
#4 /home/approach/public_html/sitecake/server/library/Zend/Application/Bootstrap/BootstrapAbstract.php(583): Zend_Application_Bootstrap_BootstrapAbstract->_bootstra in /home/approach/public_html/sitecake/server/library/Zend/Session.php on line 454

1 个答案:

答案 0 :(得分:0)

您的错误消息是:

  

必须在将任何输出发送到浏览器之前启动会话;输出在/home/approach/public_html/index.php/2

中开始

错误发生在:
/home/approach/public_html/sitecake/server/library/Zend/Session.php:454

此消息含义的完整说明已经explained in detail at another answer,我强烈建议您阅读此答案,以便更好地了解正在发生的事情。

对于您的特定案例,您似乎将sitecake_entry.php脚本包含在页面顶部,或者至少在某处之前 你初始化Zend。你想做什么,是这个(来自SiteCake示例页面):

<?php include "sitecake/server/sitecake_entry.php"; ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

我不知道Zend的细节,或者特别是您的应用程序,您可能要做的事情是找到您的HTML模板,您可以搜索项目的<!DOCTYPE目录,并添加上面的行根据示例,而不是将其添加到index.php