dongpang9573 2012-04-26 16:29 采纳率: 0%
浏览 47
已采纳

头标签显示在CakePhp的主体内部

I have a strange error on CakePhp 2.0 where the head tags renders empty, and all the tags that belongs to head, renders into the body before any content.

This his how the layout default.ctp looks:

<!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>

And this is how it's rendered, as firebug says:

<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
&#65279;&#65279;
    <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>

It's bad enough because it distorts the DOCTYPE tag and makes IE render the page very buggy.

Also, I have another test site where it doesn't happen this error. In fact I switched layouts and the error was the same.

Does someone knows why this happens? I couldn't find anything similar on the web and I don't have any clue about this. Any help will be appreciated.

Thanks in advance

  • 写回答

3条回答 默认 最新

  • duanpo7796 2012-05-29 17:10
    关注

    Finally we got the answer for this problem. It was Cake's php and the infamous character &#65279 that appeared on utf-8 encoding. By changing every encoding on php files that passed before the final layout, we solved the problem.

    Thanks for your help :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?