我们怎样才能在cakephp中包含default.ctp?

时间:2016-10-04 06:56:28

标签: php html css cakephp

我在cakephp中创建了一个网页。我有一个登录表单,在用户可以访问之前。我也创建了登录表单。我在default.ctp中编写了导航栏。由于导航栏是用default.ctp编写的,导航栏也会在登录页面中显示。但是,我不想在登录页面中显示它。我了解到我需要创建新的布局并将其包含在我的页面中。这就是我尝试的方式:

LoginController.php

<?php 
    namespace App\Controller;
    session_start ();

    use App\Controller\AppController;
    use Cake\ORM\TableRegistry;
    class LoginController extends AppController
    {
     public function loginindex(){
            $this->layout= 'loginlayout';
            $this->render ( 'login' );
        }
}

loginlayout.ctp

<?php
$cakeDescription = 'Takt Time';

use Cake\Routing\Router;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?= $this->Html->charset() ?>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>
        <?= $cakeDescription ?> ::
        <?= $this->fetch('title') ?>
    </title>

    <?= $this->fetch('meta') ?>
    <?= $this->fetch('css') ?>
    <?= $this->fetch('script') ?>
</head>
<body>
</body>
</html>

login.ctp

<?php 
    use Cake\Routing\Router;
    echo $this->Form->create(false,array('url'=>array('controller'=>'login','action'=>'loginentry'),'id'=>'myform'));
?>
<body class="page-signin">
    <div class="signin-container shadow">
        <div class="signin-info bg-primary">
            <a href="index.html" class="logo"><?php echo $this->Html->image('logo-white.png'); ?></a>
            <!-- / .logo -->
            <ul>
                <li><i class="fa fa-line-chart signin-icon"></i> Demand</li>
                <li><i class="fa fa-clock-o signin-icon"></i> Available time</li>
                <li><i class="fa fa-signal signin-icon"></i> Pulse</li>
            </ul>
            <!-- / Info list -->
        </div>
        <div class="signin-form">

            <!-- Form -->
            <form novalidate="novalidate" method="post" id="myform">
                <div class="signin-text">
                    <span>Sign In to your account</span>
                </div>
                <!-- / .signin-text -->

                <div class="form-group">
                    <div class="input-group input-group-sm">
                        <div class="input-group-addon">
                            <span class="fa fa-user"></span>
                        </div>
                        <input name="LoginID" id="LoginID" class="form-control"
                            placeholder="Username" type="text">
                    </div>
                </div>
                <!-- / Username -->

                <div class="form-group">
                    <div class="input-group input-group-sm">
                        <div class="input-group-addon">
                            <span class="fa fa-lock"></span>
                        </div>
                        <input name="Password" id="Password" class="form-control"
                            placeholder="Password" type="password">
                    </div>
                </div>
                <!-- / Password -->

                <div class="form-actions">
                    <input value="SIGN IN" class="btn btn-primary btn-sm" type="submit"
                        id="btnSave" name="btnSave"> <a href="#" class="forgot-password"
                        id="forgot-password-link">Forgot your password?</a>
                </div>
                <!-- / .form-actions -->
            </form>
</div>
            <!-- / Password reset form -->
        </div>
    </div>  
    <script type="text/javascript">
        $(document).ready(function()
        {
            jQuery.validator.setDefaults({
                errorPlacement: function(error, element) {},
                success: function(label) {}
            });
            $("#myform").validate({
                rules:
                {
                    LoginID: "required",
                    Password:"required",            
                },
                messages:
                {
                    LoginID: "Enter LoginID",
                    Password:"Enter Password"           
                }
            })
            $('#btnSave').on('click', function(){
                $("#myform").valid();
            });

            $('#forgot-password-link').click(function () {
                $('#password-reset-form').fadeIn(400);
                return false;
            });
            $('#password-reset-form .close').click(function () {
                $('#password-reset-form').fadeOut(400);
                return false;
            });
            $("#mySendPassword").validate({
                rules:
                {
                    emailid: "required",                
                },
                messages:
                {
                    emailid: "Enter EmailID",                               
                }
            })
            $('#btnSendPassword').on('click', function()
            {
                $("#mySendPassword").valid();
            });
        });
        </script>
</body>

这就是我的方式。在loginlayout.ctp中我没有在body部分写任何东西,因为我已经定制了我的home.ctp来显示登录表单。所以,我只是要显示我的登录页面,没有导航栏。

但问题是登录页面会出现导航栏。上面的代码有什么问题?我应该添加或更改什么?

0 个答案:

没有答案