In my PhotoalbumsController I am trying to load a different layout when the action imgToAlbum is called.
<?php
namespace App\Controller\Admin;
use App\Controller\AppController;
use Cake\ORM\TableRegistry;
use Cake\Http\ServerRequest;
use Cake\Event\Event;
class PhotoalbumsController extends AppController
{
public function initialize()
{
parent::initialize();
}
...
public function imgToAlbum()
{
...
$this->viewBuilder()->setLayout('ajax');
$content = 'test';
$this->set(compact($content));
}
I am getting this error:
Error: The view for PhotoalbumsController::imgToAlbum() was not found.
Confirm you have created the file: "Admin/Photoalbums/img_to_album.ctp" in one of the following paths
I've also tried $this->viewBuilder()->setTemplate('ajax');
and $this->viewBuilder()->template('ajax');
. But these don't work either.
I use the same trick in my AppController for my backend, ie, this works:
public function beforeRender(Event $event)
{
parent::beforeRender($event);
if($this->request->getParam('prefix') and $this->request->getParam('prefix') == 'admin') {
$this->viewBuilder()->setLayout('admin');
}
}
What am I missing here.