- Code: Select all
-table=cal_data&-action=get_json
I'm sure this is easy, I just can't wrap my mind around it yet.
Adding an action to return a JSON feed
8 posts
• Page 1 of 1
Adding an action to return a JSON feedI'm trying to use this calender widget on my dashboard page. In order to do so, I need to get a JSON feed from another table. It has a pretty specific requirement for the feed, so I think it's best to roll my own JSON action. I've searched through the forums and wiki, and am a little confused on how I can do this. Can I just define a new action in {site_dir}/actions/get_json.php then call it on the uri line like this?
I'm sure this is easy, I just can't wrap my mind around it yet.
Re: Adding an action to return a JSON feedThat's pretty much right. Check out this section from the Getting Started tutorial for an example:
http://xataface.com/documentation/tutor ... ce_actions -Steve
Re: Adding an action to return a JSON feedI ended up doing this:
Am I breaking anything by doing the echo from the action, instead of going through the smarty template? Also, how do I pass/receive custom parameters to the action?
Re: Adding an action to return a JSON feedYou can get parameters the same way you do in any PHP script (e.g. $_GET or $_POST). In addition you could use the Dataface_Application::getQuery() method which returns a massaged version of the query parameters (it guarantees at least -table and -action will be set).
One thing to note. You should return a request header to let clients know that the data type is JSON. Some browsers may choke if you don't. You may want to refer to the export_json action that is defined in the xataface actions/export_json.php file for pointers. -Steve
Re: Adding an action to return a JSON feedOne other thing to notice is that you don't have any permissions or security set up on your action so it will be available to the world. If this is public data, fine. If not, you should implement some security.
-Steve
Re: Adding an action to return a JSON feedThanks, Steve. Authentication will be handed by the web server (we have an LDAP server here and use mod_ldap).
Re: Adding an action to return a JSON feedAll the same, I suggest the following change:
to
Note the line:
This will just guarantee that users who don't have the 'view' permission for an event won't see it. If you aren't using Xataface permissions, then users are granted all permissions and this will still work. If you start to use Xataface permissions later, this action will respect those permissions. -Steve
Re: Adding an action to return a JSON feedDone, and added the JSON header as well. I'll admit to being a little sloppy when trying to push something out the door.
8 posts
• Page 1 of 1
Who is onlineUsers browsing this forum: No registered users and 0 guests |