Cakephp: isAjax weirdness
Currently, I’m doing a project in CakePHP.
There’s lots to say about cake, here just a quick note, for myself or for anyone in case you are running into the same problem.
Situation: you are using the Ajax helper, which contains a method isAjax()
– returns true
if the request was an Ajax request.
Typically, you use this method inside a view, to conditionally render content for regular/ajax views. Example:
...
if (! $ajax->isAjax()) {
// render general page stuff
}
// render stuff for both regular- and ajax view
...
My problem was that the isAjax()
call never returned true, regardless of ajax/regular request method.
The solution appears to be really simple: you should include the 'RequestHandler'
component in your controller class. This one took me way too long to figure out!
public $components = array (
'Auth',
'Cookie',
'RequestHandler'
);
Update my situation was even worse than described above; I use a redirect between controllers within an Ajax call, something which is officially supported by Cake 1.2. This worked just fine in Safari, but not in Firefox (and Opera) – these browsers would not load the Ajax view but rather the complete page, almost crashing the server by consuming huge amounts of memory.
Read on… (More …)
Thanks for the mention Johannes. I am also curious – the third blog entry lists at the bottom both proponents and detractors of GM in the enterprise. People are doing it, but the security and deployment issues cannot be ignored. BEA (my employer) focuses on server side solutions where we don’t have these issues.
In the enterprise portal space, which is my focus, our customers are looking to integrate legacy web applications and packaged apps into a standardized and centralized infrastructure. They are looking to reduce costs by combating the sprawl of having thousands of web applications in their enterprise. Portals are a good solution to this problem.
But to implement a portal solution, those legacy web applications must be integrated. There are a variety of approaches, including programmatic integration using Web Services, web clipping, WSRP, iframes, etc.
I am interested in Greasemonkey because it is yet another tool to add to the bag of tricks when repurposing web applications. It likely wouldn’t be used in conjunction with an enterprise portal, but it is interesting all the same.
Cheers,
Peter