开发者

CakePHP Login Layout

开发者 https://www.devze.com 2023-01-28 08:12 出处:网络
I created a login view for my Employee controller, but when the login view renders, it shows up as a plain white page (not the layout from my default.ctp).

I created a login view for my Employee controller, but when the login view renders, it shows up as a plain white page (not the layout from my default.ctp).

I tried calling $this->layout = 'default'; from the login action,

but it sounds like that code will not execute until after the view has posted.

controllers/employee_controller.php

function login() {
    $this->layout = 'default';
}

views/layouts/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>
        <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>

views/employees/login.ctp

<?= 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>


After seeing your code, this is most certainly due to CSS path being incorrect. Can you replace the line calling your stylesheet with the code I've given below?
<?php print $html->css('cake.generic.css'); ?>

0

精彩评论

暂无评论...
验证码 换一张
取 消