0

我正在尝试将布局设置为 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');
}
4

1 回答 1

0

如果您有多种布局,请尝试这种方式。如果你第一次想要它空白(不是造型......等)

这是您要空白或分配新布局的示例控制器。类 FrontsController 扩展 AppController { public $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>
于 2019-10-26T06:39:13.130 回答