Zikula Network
Subscribe!
Why I love Zikula (Reason #768)
Today I had a problem: I am working on a theme that is supposed to use AJAX. Now Zikula only offers it's own AJAX solution for modules only. And I asked on the developers' list how I can solve this problem. And I thought I get a low level do it yourself AJAX recommendation. But au contraire...
Themes allow you to override and expant almost everything, modules can do. You can override templates, CSS add plugins and so on. Modules on the other hand can get extended with extra functions. So if you need an additional user API function for "strangersModule" you can add that like this:
/config/functions/strangersModule/pnuserapi/youfunction.php
Within this file you write your function as if it was in:
/modules/strangersModule/pnuserapi.php
The same works for all the files in a module root. So if you need a AJAX function for your customized templates in a module that doesn't yet have a pnajax.php you can add this in the same manner:
/config/functions/strangersModule/pnajax/youfunction.php
This prevents hacks of modules that get lost with the next update.
Now what I learned from Mateo today: You can also add these extra functions also in a theme:
/themes/MYTHEME/functions/strangersModule/pnajax/yourfunction.php
As my function is not a module specific but theme specific function I added it to the Theme module. And as the Theme module is a system module I can rely on it's presence in the system:
/themes/MYTHEME/functions/strangersModule/pnajax/myfunction.php
This proved to me once again that Zikula is all about creativity. Zikula offers so many cool things and sometime I think we haven't yet started to meter its potential.
Share This | Print
Trackbacks
(The URL to TrackBack this entry is: http://blog.zikula.org/index.php?module=TrackBack&id=26,1-61). If your blog does not support Trackbacks you can manually add your trackback by using this form.Comments
There's an issue adding ajax functions to the theme: They will not work if your ajax request uses the ajax.php entrypoint. They will work using the index.php.
So, the JS code to perform the Ajax request should look like this:
Code
- var pars = "module=modName&type=ajax&func=funcName"
- var myAjax = new Ajax.Request(
- "index.php",
- {
- method: 'post',
- parameters: pars,
- onComplete: myfunction_response
- });
all this years loving Zikula and I haven't find before such perfect word to explain my love: CREATIVITY
That word must be in our slogan don't you think? B-)
If you'll return data from that function, lets say that we have a $data array to return as Ajax response, that ajax function may finish with this line:
Code
- AjaxUtil::output($data, false, false);
Code
- pnShutDown();
AjaxUtil::output contains a call for pnShutDown()
If not, then should shutdown the system directly with no pail
This customization or extension method only is used if the module in question already offers those "type of functions".
/modules/strangersModule/pnajax.php or /config/functions/strangersModule/pnajax.php must exist to be able to put ajax functions in the Theme.
For instance, you can't add Theme (system module) ajax functions in YourTheme because it doesn't have ajax functions, you may use the Users module instead.
Aha, so as I am hardcalling the function anyway, I can also call it as a user type function, can't I?
But it's ugly to use AjaxUtil in a different controller than pnajax IMHO
But if you want, nobody is stopping you to do so, but it's not as beautiful as put the stuff where it fits better (developer point of view, again





Latest Comments