I want to set $this->layout to json in the controller action.
In the json layout, there will be a line saying $this->Javascript>object(); which will parse through the data given to it by the controller, and output the jSON.
However, creating a new view file for each jSON request, eg. recipe_view, ingredient_view isn’t necessary, I just need a layout.
Is there a way to bypass the view file altogether and have just the layout, without the notorious Missing View! error?
@pleasedontbelong’s solution works. You can also create a layout and view for ajax.
Your layout can be something like this:
And then you can create an ajax view like this:
And then from your controller…