简体   繁体   中英

Head tags displays inside body on 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

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 :)

you have file with BOM char . use BOM Detector program

java : http://www.javapractices.com/topic/TopicAction.do?Id=257 [recommended][find and remove]

1- check URL for exist BOM
2- remove BOM from your file
php : http://www.dotvoid.com/2010/04/detecting-utf-bom-byte-order-mark/

You are missing one end tag in the layout file.

    <body>
        <div id="container">
            <div id="header">
            </div>
    (the rest of the html render)
    </body>
    </html>

It should be corrected as follows

    <body>
        <div id="container">
            <div id="header">
            </div>
    (the rest of the html render)
        </div>
    </body>
    </html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM