CakePHP登录布局

CakePHP登录布局,php,cakephp,Php,Cakephp,我为我的员工控制器创建了一个登录视图,但当登录视图呈现时,它显示为纯白色页面(不是默认.ctp中的布局) 我试着调用$this->layout='default'来自登录操作, 但听起来,在视图发布之前,代码不会执行 控制器/employee\u controller.php function login() { $this->layout = 'default'; } <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transit

我为我的
员工控制器
创建了一个登录视图,但当登录视图呈现时,它显示为纯白色页面(不是默认.ctp中的布局)

我试着调用
$this->layout='default'来自登录操作,
但听起来,在视图发布之前,代码不会执行

控制器/employee\u controller.php

function login() {
    $this->layout = 'default';
}
<!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>
        <title><?php echo $title_for_layout; ?></title>
        <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
        <link rel="stylesheet" type="text/css" href='<?php echo "css".DS."cake.generic.css" ?>' />
    </head>
    <body>
    <div id="parentDiv">
        <div id="menu">
            <div id="messages">
            </div>
        </div>
        <div id="header">
            <?= $this->element('search'); ?>
        </div>
        <div id="content">
            <?php echo $content_for_layout; ?>
        </div>
    </div>
    </body>
</html>
<?= debug($this); ?>
<div>
    <div style="border: black solid 1px">
        <?php
        /*
         * To change this template, choose Tools | Templates
         * and open the template in the editor.
         */
        echo $this->Form->create('Employee', array('url' => array('controller' => 'employees', 'action' => 'login')));
        echo $this->Form->input('username');
        echo $this->Form->input('password');
        echo $this->Form->submit('Login');
        echo $this->Form->end();
        ?>
    </div>
</div>
视图/布局/default.ctp

function login() {
    $this->layout = 'default';
}
<!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>
        <title><?php echo $title_for_layout; ?></title>
        <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
        <link rel="stylesheet" type="text/css" href='<?php echo "css".DS."cake.generic.css" ?>' />
    </head>
    <body>
    <div id="parentDiv">
        <div id="menu">
            <div id="messages">
            </div>
        </div>
        <div id="header">
            <?= $this->element('search'); ?>
        </div>
        <div id="content">
            <?php echo $content_for_layout; ?>
        </div>
    </div>
    </body>
</html>
<?= debug($this); ?>
<div>
    <div style="border: black solid 1px">
        <?php
        /*
         * To change this template, choose Tools | Templates
         * and open the template in the editor.
         */
        echo $this->Form->create('Employee', array('url' => array('controller' => 'employees', 'action' => 'login')));
        echo $this->Form->input('username');
        echo $this->Form->input('password');
        echo $this->Form->submit('Login');
        echo $this->Form->end();
        ?>
    </div>
</div>

views/employees/login.ctp

function login() {
    $this->layout = 'default';
}
<!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>
        <title><?php echo $title_for_layout; ?></title>
        <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
        <link rel="stylesheet" type="text/css" href='<?php echo "css".DS."cake.generic.css" ?>' />
    </head>
    <body>
    <div id="parentDiv">
        <div id="menu">
            <div id="messages">
            </div>
        </div>
        <div id="header">
            <?= $this->element('search'); ?>
        </div>
        <div id="content">
            <?php echo $content_for_layout; ?>
        </div>
    </div>
    </body>
</html>
<?= debug($this); ?>
<div>
    <div style="border: black solid 1px">
        <?php
        /*
         * To change this template, choose Tools | Templates
         * and open the template in the editor.
         */
        echo $this->Form->create('Employee', array('url' => array('controller' => 'employees', 'action' => 'login')));
        echo $this->Form->input('username');
        echo $this->Form->input('password');
        echo $this->Form->submit('Login');
        echo $this->Form->end();
        ?>
    </div>
</div>

看到您的代码后,这肯定是因为CSS路径不正确。你能用我下面给出的代码替换调用样式表的行吗

创建视图后,您可以通过编辑core.php文件检查错误,并将调试模式设置为2@nik,谢谢你的建议。是的,有一个视图(我知道这是一个事实,因为我看到了带有登录文本框和按钮的视图渲染),调试没有告诉我任何事情(我在2上有调试)。哦!除非看一下文件,否则我说不出这个问题。在我的例子中,我从来没有提到默认布局。我很困惑-你说你得到一个空白页面,然后你说你可以看到表单!您是在谈论登录后视图吗?顺便说一句,如果您使用的是CakePHP 1.3,并且将debug设置为2,则除非您在布局或视图中添加了某个位置,否则将不会看到数据库调试-请参见.htaccess文件,所有文件都与本书中的一行对应。我不知道你说的“强制加载数据库”是什么意思?有关更多代码,请参阅我的编辑。另外,请使用提供给您的帮助程序,这不是问题。