我正在尝试将布局设置为blank.ctp,但是它不起作用,我已经在src / Template / Layout中创建了blank.ctp,但是以下代码不起作用,因为在blank.ctp文件中显示的是默认布局。
public function delete($id = null)
{
$this->request->allowMethod(['get']);
$this->loadModel('AdminLTETasks');
$adminLTETask = $this->AdminLTETasks->get($id);
if ($this->AdminLTETasks->delete($adminLTETask)) {
echo 'The admin l t e task has been deleted.';
} else {
echo 'The admin l t e task could not be deleted. Please, try again.';
}
$this->viewBuilder()->setLayout('blank');
}
我也尝试过时的方法layout('blank'),它也不起作用
public function delete($id = null)
{
$this->request->allowMethod(['get']);
$this->loadModel('AdminLTETasks');
$adminLTETask = $this->AdminLTETasks->get($id);
if($adminLTETask->user_id == $this->Auth->user('id')) {
if ($this->AdminLTETasks->delete($adminLTETask)) {
echo 'The admin l t e task has been deleted.';
} else {
echo 'The admin l t e task could not be deleted. Please, try again.';
}
}
$this->viewBuilder()->layout('blank');
}
如果您有多种布局,请尝试这种方式。如果您想让它第一次为空白(不设置样式等)
这是您要空白或分配新布局的示例控制器。FrontsController类扩展了AppController {公开的$ title;
public function initialize()
{
parent::initialize();
$this->Auth->allow(['index']);
$this->viewBuilder()->layout('frontend');
}
public function index() {
}
}
以及您的frontend.ctp布局示例。
<!DOCTYPE html>
<html lang="en">
<head>
<?= $this->element('Fronts/head') ?>
</head>
<body>
<?= $this->element('Fronts/header') ?>
<!-- Page Content -->
<div id="content" class="container">
<?= $this->Flash->render() ?>
<div class="row">
<?= ($this->request->getParam('action') == 'index') ? 'LIST' : strtoupper($this->request->getParam('action')); ?>
<?= $this->fetch('content') ?>
</div>
</div>
<?= $this->element('Fronts/footer') ?>
</body>
</html>