我刚刚用composer安装了cakephp 3.0.3,我正在运行内置的开发蛋糕服务器来查看我的网站。我只对项目进行了两次更改。在使用该项目一段时间之后,我意识到我的页面上没有加载default.ctp布局。
我做的第一件事是配置与MySQL的数据库连接。我想做的下一件事是包括bootstrap和jQuery。当然,我按照cakephp食谱,将css和js放在webroot下的相应文件夹中。接下来,我链接到src / Templates / Layout / default.ctp中的那些文件。
首先,当他们没有出现时,我猜测链接它们的命令一定是个问题,但是当我尝试添加要在default.ctp中显示的其他内容时,我意识到布局没有呈现一点都不。
我对cakephp和php完全不熟悉,但我直接从食谱中读到并按照他们的例子,我不知道为什么默认布局根本不会加载。
我尝试将appController更改为包含$this->layout = 'default';
的{{3}},但这只是给了我一个严格的错误,说appController beforeRender()必须与Controller beforeRender()兼容,所以我只是更改了它回到默认的方式。
我正在使用OS X优胜美地和谷歌浏览器查看该页面,如果这有所不同。默认主页上的所有内容都有复选标记,说明所有内容都已正确安装和配置,我看到其他人有类似问题,其中mod_rewrite是他们的问题,但我没有任何关于mod_rewrite的错误。
这是我的default.ctp:
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 0.10.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
$cakeDescription = "Children's Medical Group";
?>
<!-- This layout is loaded for controller view content -->
<!DOCTYPE html>
<html>
<head>
<?= $this->Html->charset() ?>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>
<?= $cakeDescription ?>:
<?= $this->fetch('title') ?>
</title>
<?= $this->Html->meta('icon') ?>
<?= $this->Html->css('base.css') ?>
<?= $this->Html->css('cake.css') ?>
<?= $this->fetch('meta') ?>
<!-- The following css and js elements are for bootstrap -->
<!-- Latest compiled and minified CSS -->
<!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> -->
<?= $this->Html->css('bootstrap.min.css') ?>
<!-- Optional theme -->
<!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css"> -->
<?= $this->Html->css('bootstrap-theme.min.css') ?>
<!-- Not actually sure what this does -->
<?= $this->fetch('css') ?>
</head>
<body>
<header>
<div class="header-title">
<span><?= $this->fetch('title') ?></span>
</div>
<div class="header-help">
<span><a target="_blank" href="http://book.cakephp.org/3.0/">Documentation</a></span>
<span><a target="_blank" href="http://api.cakephp.org/3.0/">API</a></span>
</div>
</header>
<div id='.jumbotron'>
Testing both bootstrap and default.ctp to see if this shows
</div>
<div id="container">
<div id="content">
<?= $this->Flash->render() ?>
<div class="row">
<?= $this->fetch('content') ?>
</div>
</div>
<footer>
</footer>
</div>
<!-- Latest compiled and minified Bootstrap JavaScript -->
<!-- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> -->
<?= $this->Html->script('bootstrap.min.js'); ?>
<!-- Bootstrap requires jQuery to run bootstrap.js-->
<?= $this->Html->script('jquery-1.11.3.min.js'); ?>
<!-- Not actually sure what this does -->
<?= $this->fetch('script') ?>
</body>
</html>
以及我在访问here时看到的html源代码:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
CakePHP: the rapid development php framework </title>
<link href="/favicon.ico" type="image/x-icon" rel="icon"/><link href="/favicon.ico" type="image/x-icon" rel="shortcut icon"/> <link rel="stylesheet" href="/css/base.css"/> <link rel="stylesheet" href="/css/cake.css"/></head>
<body class="home">
<header>
<div class="header-image">
<img src="http://cakephp.org/img/cake-logo.png" alt=""/> <h1>Get the Ovens Ready</h1>
</div>
</header>
<div id="content">
<p id="url-rewriting-warning" style="background-color:#e32; color:#fff;display:none">
URL rewriting is not properly configured on your server.
1) <a target="_blank" href="http://book.cakephp.org/3.0/en/installation/url-rewriting.html" style="color:#fff;">Help me configure it</a>
2) <a target="_blank" href="http://book.cakephp.org/3.0/en/development/configuration.html#general-configuration" style="color:#fff;">I don't / can't use URL rewriting</a>
</p>
<div class="row">
<div class="columns large-5 platform checks">
<p class="success">Your version of PHP is 5.4.16 or higher.</p>
<p class="success">Your version of PHP has the mbstring extension loaded.</p>
<p class="success">Your version of PHP has the openssl extension loaded.</p>
<p class="success">Your version of PHP has the intl extension loaded.</p>
</div>
<div class="columns large-6 filesystem checks">
<p class="success">Your tmp directory is writable.</p>
<p class="success">Your logs directory is writable.</p>
<p class="success">The <em>FileEngine</em> is being used for core caching. To change the config edit config/app.php</p>
</div>
</div>
<div class="row">
<div class="columns large-12 database checks">
<p class="success">CakePHP is able to connect to the database.</p>
</div>
</div>
<div class="row">
<div class="columns large-6">
<h3>Editing this Page</h3>
<ul>
<li>To change the content of this page, edit: src/Template/Pages/home.ctp.</li>
<li>You can also add some CSS styles for your pages at: webroot/css/.</li>
</ul>
</div>
<div class="columns large-6">
<h3>Getting Started</h3>
<ul>
<li><a target="_blank" href="http://book.cakephp.org/3.0/en/">CakePHP 3.0 Docs</a></li>
<li><a target="_blank" href="http://book.cakephp.org/3.0/en/tutorials-and-examples/bookmarks/intro.html">The 15 min Bookmarker Tutorial</a></li>
<li><a target="_blank" href="http://book.cakephp.org/3.0/en/tutorials-and-examples/blog/blog.html">The 15 min Blog Tutorial</a></li>
</ul>
<p>
</div>
</div>
<hr/>
<div class="row">
<div class="columns large-12">
<h3 class="">More about Cake</h3>
<p>
CakePHP is a rapid development framework for PHP which uses commonly known design patterns like Front Controller and MVC.
</p>
<p>
Our primary goal is to provide a structured framework that enables PHP users at all levels to rapidly develop robust web applications, without any loss to flexibility.
</p>
<ul>
<li><a href="http://cakefoundation.org/">Cake Software Foundation</a>
<ul><li>Promoting development related to CakePHP</li></ul></li>
<li><a href="http://www.cakephp.org">CakePHP</a>
<ul><li>The Rapid Development Framework</li></ul></li>
<li><a href="http://book.cakephp.org/3.0/en/">CakePHP Documentation</a>
<ul><li>Your Rapid Development Cookbook</li></ul></li>
<li><a href="http://api.cakephp.org/3.0/">CakePHP API</a>
<ul><li>Quick Reference</li></ul></li>
<li><a href="http://bakery.cakephp.org">The Bakery</a>
<ul><li>Everything CakePHP</li></ul></li>
<li><a href="http://plugins.cakephp.org">CakePHP plugins repo</a>
<ul><li>A comprehensive list of all CakePHP plugins created by the community</li></ul></li>
<li><a href="https://groups.google.com/group/cake-php">CakePHP Google Group</a>
<ul><li>Community mailing list</li></ul></li>
<li><a href="irc://irc.freenode.net/cakephp">irc.freenode.net #cakephp</a>
<ul><li>Live chat about CakePHP</li></ul></li>
<li><a href="https://github.com/cakephp/">CakePHP Code</a>
<ul><li>For the Development of CakePHP Git repository, Downloads</li></ul></li>
<li><a href="https://github.com/cakephp/cakephp/issues">CakePHP Issues</a>
<ul><li>CakePHP issues and pull requests</li></ul></li>
</ul>
</div>
</div>
</div>
<footer>
</footer>
<script>var __debug_kit_id = 'cade8b34-e4ea-4601-a30e-a3a941ddf855', __debug_kit_base_url = 'http://localhost:8765/';</script><script src="/debug_kit/js/toolbar.js"></script></body>
</html>
答案 0 :(得分:5)
您已安装CakePHP 应用程序模板的3.0.3版,实际的CakePHP 框架是不同的(请参阅bin/cake --help
或{{ 1}})。建议你提两个版本!
不要使用为旧版本制作的问题/答案,教程等,除非您知道自己在做什么,即知道如何迁移代码。您链接的问题是关于CakePHP 1.3,它与它不兼容。
您正在查看默认主页(通过现成的pages controller发送),在模板文件本身中使用vendor/cakephp/cakephp/VERSION.txt
明确turns off the layout usage $this->layout = false;
)。
因此,创建自己的页面,除非您明确禁用该行为,否则它们将使用默认布局。如果你想更改主页,请按照页面本身的说法进行操作
要更改此页面的内容,请编辑:src / Template / Pages / home.ctp
答案 1 :(得分:3)
$this->viewBuilder()->layout('default');
答案 2 :(得分:0)
您可以使用以下内容: - $这 - &GT; viewBuilder() - &GT;布局( 'LAYOUT_NAME');
我不确定但它应该有用......