Hi,
i've added a checkbox in my image.php and i need to setup an ajax request to send the checkbox value when it's clicked and update the current image information in database.
I've already added the necessary fields to database, get and set functions to class-image.php no problem with that.
What's the best file/url to call for my request?
I need then to call my class-image.php set function to save the necessary data of the current image, probably i'll need to create an image object for that, right?
Quote:I've already added the necessary fields to database, get and set functions to class-image.php no problem with that.
If you mean you have both change the main images database table and the core image class I strongely suggest to rethink that way.
If you need extra methods for the image class you should use object orientation to extend the class with what you need extra.
As for the database table you should be using the plugin_storage table for that reason.
As for the ajax request you should not be needing to call the core class. You should use a plugin or theme functionality for that. A custom theme page also would work.
Hmm.. i followed this post http://www.zenphoto.org/support/topic.php?id=1217#post-6820
i know it is very old but i didn't find out anything more recent.
I found it strange be able to add fields to image database table..
Can i add fields to plugin_storage table or i have to use the current columns?
It makes more sense the way you're saying because it will be a pain to update zp in the future the way i'm doing it.
A lot changed since the early days of Zenphoto. The plugin_storage table was exactly introduce to have theme or plugins authors have a place for custom storage.
It is recommended to not add fields to the plugin_storage table and use the ones provide. It is also part of Zenphoto. Some recomended usage of the three fields:
Of course if you need really special things you can always create complete custom tables and write something to use them.
Technically you might be able to do it as a theme custom function as well. But maybe what you want to do is of use for others so you might want to make it available as a plugin later on.
There is a tutorial about plugins:
http://www.zenphoto.org/news/zenphoto-plugin-architecture
Within that a plugin ndemo file is linked which shows a basic structure:
https://github.com/zenphoto/DevTools/tree/master/demo_plugin-and-theme
A plugin that uses the plugin_storage table is for example the multiple_layouts one.
Best you should also have read the theming tutorial and the object model tutorial.
Themes support a functions.php file that loads automatically if present. Unless you want to add checkboxes or else to the backend pages you don't need a plugin. Of course it does not hurt to do it like that even if it is not generally usable for others.
Besides the default theme structure you can create anything additionally within your theme. Even that structure you can leave if you have the knowledge.
A picture approval system? A kind of clients selecting what they like to buy or something? Then you should maybe take a look at the favorites plugin. Might server your purpose already. Also the rating plugin could server as a similar purpose (e.g five stars = approved).
Yes i know that, but i need to save and expose the date it was approved. I really need it works this way.
I did as you said added the functions i needed to themes folder functions.php. I've created a controller.php in themes folder to handle with checkbox ajax request call the desired functions.php function and update the plugin_storage table. I've included the functions.php in controller.php but when i do the ajax request to controller.php error is thrown "Call to undefined function zp_register_filter() in functions.php on line 2".
Of course this is related how the files are included..
How to make sure my controller.php has all preceding includes needed so i can use functions.php functions?
Actually it is quite simple if using jQuery. Here some basic examples:
To send something to a page that has ZP stuff available:
$.ajax({ url: "/page/" });
http://api.jquery.com/jQuery.ajax/
To load somehting here a custom theme page as well so the function are all avaiable:
$("#element-to-load-to").load("/page/");
http://api.jquery.com/load/