Error when view file does not exist #1

fly2279 opened this Issue Dec 29, 2011 · 4 comments


None yet

4 participants

fly2279 commented Dec 29, 2011

When using 'Setting json variable in Controller' method there is an error if the view file for that action does not exist. The offending code is on line 47 where $view !== false in the if statement. It should be $view !== null.

gfarrell commented Jan 2, 2012

I'm also getting the error:

Missing View
Error: The view for RoomsController::index() was not found.
Error: Confirm you have created the file: .../app/View/Rooms/json.json.ctp

My controller code is:

$rooms = $this->paginate('Room');
if($this->params['json']) {
    $this->view = 'Json.Json';
    $this->set('json', $rooms);     
rikdc commented Jan 3, 2012

To change the view within a method, I found that instead of using $this->view, use $this->viewClass variable will work.

$this->viewClass = 'Json.Json';

gfarrell commented Jan 3, 2012

You also have to use $this->render(false) if you do not want to use a view file.

@jrbasso jrbasso closed this in cbe1b49 Jan 4, 2012
jrbasso commented Jan 4, 2012

Thank you guys, I changed the code to support both false and null as parameter in render. So it makes backward compatible and fix the issue. Thanks for all your help and sorry by delay, I was in vacation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment