I would like an action in one of my controllers to output plain javascript, but I can’t find anything in the Book on the proper way to achieve this.
I’ve tried $this->response->type('js'); which does set the Content-Type: text/javascript; charset=UTF-8 but doesn’t change the layout to Layouts/js/default.ctp
I keep finding posts all over saying to use $this->RequestHandler->renderAs($this, 'js')
but it’s as if that method no longer exists: What’s the usage of app\views\layouts\js?
The only thing that has worked so far is $this->layoutPath = "js"; according to: How to change cakephp layout?
However, this article seems to be from Cake 1.3 days. Is this still the correct way to do switch to the js layout?
RequestHandlerComponent::renderAsstill exists:http://book.cakephp.org/2.0/en/core-libraries/components/request-handling.html#RequestHandlerComponent::renderAs
Don’t forget to include the Request Handler component in your controller, and then it should work fine.