以下标题添加到我在CAKEPHP 2.XXX中的index.ctp .... 我该如何删除它?
你去:
<div id="header">
<h1><a href="http://cakephp.org">CakePHP: the rapid development php framework</a></h1>
</div>
这是我的index.ctp文件
<h1>Blog posts</h1>
<p><?php echo $this->Html->link("Add Post", array('action' => 'add')); ?></p>
<table>
<tr>
<th>Id</th>
<th>Title</th>
<th>Action</th>
<th>Created</th>
</tr>
<!-- Here's where we loop through our $posts array, printing out post info -->
<?php foreach ($posts as $post): ?>
<tr>
<td><?php echo $post['Post']['id']; ?></td>
<td>
<?php
echo $this->Html->link(
$post['Post']['title'], array('action' => 'view', $post['Post']['id'])
);
?>
</td>
<td>
<?php
echo $this->Form->postLink(
'Delete', array('action' => 'delete', $post['Post']['id']), array('confirm' => 'Are you sure?')
);
?>
<?php
echo $this->Html->link(
'Edit', array('action' => 'edit', $post['Post']['id']), array('confirm' => 'EDIT ?')
);
?>
</td>
<td>
<?php echo $post['Post']['created']; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
帮帮我PLZ ....
我尝试在“app / layouts”中添加default.ctp但我的应用程序不起作用...它只显示default.ctp但不显示我的index.ctp
以下是我的Controller文件......
<?php
class PostsController extends AppController {
public $helpers = array('Html', 'Form');
public function index() {
$this->set('posts', $this->Post->find('all'));
}
public function view($id = null) {
if (!$id) {
throw new NotFoundException(__('Invalid post'));
}
$post = $this->Post->findById($id);
if (!$post) {
throw new NotFoundException(__('Invalid post'));
}
$this->set('post', $post);
}
public function add() {
if ($this->request->is('post')) {
$this->Post->create();
if ($this->Post->save($this->request->data)) {
// $this->Session->setFlash(__('Your post has been saved.'));
return $this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('Unable to add your post.'));
}
}
public function edit($id = null) {
if (!$id) {
throw new NotFoundException(__('Invalid post'));
}
$post = $this->Post->findById($id);
if (!$post) {
throw new NotFoundException(__('Invalid post'));
}
if ($this->request->is(array('post', 'put'))) {
$this->Post->id = $id;
if ($this->Post->save($this->request->data)) {
// $this->Session->setFlash(__('Your post has been updated.'));
return $this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('Unable to update your post.'));
}
if (!$this->request->data) {
$this->request->data = $post;
}
}
public function delete($id) {
if ($this->request->is('get')) {
throw new MethodNotAllowedException();
}
if ($this->Post->delete($id)) {
//$this->Session->setFlash(__('The post with id: %s has been deleted.', h($id)) );
return $this->redirect(array('action' => 'index'));
}
}
}
?>
答案 0 :(得分:1)
使用以下行更改默认布局 -
public function index() {
$this->layout= 'home'; // new name of layout that you are going to assign
$this->set('posts', $this->Post->find('all'));
}
并将其他文件名home.ctp放在APP / VIEW / layout /
中通过在您的cake / lib / view / layout目录中复制原始默认布局default.php,并根据需要删除页脚内容。
你的home.ctp应该像 -
<!DOCTYPE html>
<html lang="en">
<head>
<title><?php echo $title_for_layout?></title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<!-- Include external files and scripts here (See HTML helper for more info.) -->
<?php
echo $this->fetch('meta');
echo $this->fetch('css');
echo $this->fetch('script');
?>
</head>
<body>
<!-- If you'd like some sort of menu to
show up on all of your views, include it here -->
<div id="header">
<div id="menu">...</div>
</div>
<!-- Here's where I want my views to be displayed -->
<?php echo $this->fetch('content'); ?>
<!-- Add a footer to each displayed page -->
<div id="footer">...</div>
</body>
</html>
答案 1 :(得分:1)
在你的行动中,make layout等于false
$this->layout= '';
这将迫使cakephp不包括您的应用程序的任何布局。
如果您想使用自定义布局,请按照以下链接中的步骤进行操作