我在 CakePhp 2.0 上遇到一个奇怪的错误,其中 head 标签呈现为空,并且属于 head 的所有标签都在任何内容之前呈现到正文中。
这就是布局 default.ctp 的样子:
<!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>
<?php echo $this->Html->charset(); ?>
<title>
<?php echo $title_for_layout; ?>
</title>
<?php
echo $this->Html->meta('icon');
echo $this->Html->script(array('librerias/jquery.tools.min'));
echo $this->Html->css('cake.generic');
echo $this->Html->css('webfront');
echo $scripts_for_layout;
?>
</head>
<body>
<div id="container">
<div id="header">
</div>
(the rest of the html render)
</body>
</html>
这就是它的渲染方式,正如 firebug 所说:
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>

<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title> Usuarios </title> **(IE moves the title tag on the head manually, it seems)**
**(IE displays the DOCTYPE on its debugging console here)**
<link rel="icon" type="image/x-icon" href="/web/favicon.ico">
<link rel="shortcut icon" type="image/x-icon" href="/web/favicon.ico">
<script src="/web/js/librerias/jquery.tools.min.js" type="text/javascript">
<link href="/web/css/cake.generic.css" type="text/css" rel="stylesheet">
<link href="/web/css/webfront.css" type="text/css" rel="stylesheet">
<div id="container">
<div id="header"> </div>
(the rest of the html render)
</body>
</html>
这已经够糟糕的了,因为它扭曲了 DOCTYPE 标记并使 IE 渲染页面时出现很多错误。
此外,我还有另一个测试站点,不会发生此错误。事实上我切换了布局,错误是一样的。
有人知道为什么会发生这种情况吗?我在网上找不到类似的东西,对此我没有任何线索。任何帮助将不胜感激。
提前致谢
最佳答案
终于我们找到了这个问题的答案。这是Cake的php和utf-8编码上出现的臭名昭著的字符。通过更改最终布局之前通过的 php 文件的每个编码,我们解决了问题。
感谢您的帮助:)
关于php - Head 标签显示在 CakePhp 的 body 内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10337532/