function beforeRender()
{
if ($this->RequestHandler->isAjax())
{
$this->viewPath = $this->viewPath.'/ajax'; // change the view directory
# $this->ext = '.jhtml'; // or change the extension
}
}
So now when an action is called by an ajax script, Cake sees this and changes the view path, and calls the following view app/views/controller/ajax/action.thtml.
Alternatively you can have the extension of your view files changed. So all ajax calls would call views ending in .jhtml for example. Your choice!
So now my ajax views are separated from my normal views.
This site contains the musings of Joel Moss, and is powered by Codaset pages; a simple, yet powerful way to host your static site. Just commit and push your site to your free Git repository at Codaset, and that's it!
Tell me more about Joel »Related Articles...
- Dynamic Form and Dynamic Errors for Rails 3
- Handling Dates in MongoDB
- Converting HTML Entities to Characters with Javascript
- jQuery UI Autocomplete and Caching Query Results
- Trigger Javascript Events after Binding with jQuery
- Tail your Logs with a Touch of Color
- Introducing [Baby] Mario: Content Management Made Easy
- Taking this Blog to a better Place.
- Easily Manage your Local Hosts with Ghost
- I finally did it! My own Web Development Podcast
