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?
Comments
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.
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.
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:
1. An identifier of your action ( like "mycustomplugin">
2. the identifier of the item to attach the data to ('myitem').
3. The actual value. If you need more fields you can use serialization for example or just more rows per item.
Since this table can be used for anything it is not covered by the object model. You have to use plain sql queries.
Of course if you need really special things you can always create complete custom tables and write something to use them.
Can you recommend some example of plugin to follow?
Best practices to develop plugins to zenphoto?
Thank you.
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.
I just have to create the php files i need inside theme folder?
Thank you.
Besides the default theme structure you can create anything additionally within your theme. Even that structure you can leave if you have the knowledge.
Thank you very much for your help.
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?
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/