Forum
Functions in runtime.php needing to be accessed via AJAX
Hi guys,
I'm trying to develop a really small app for Perch, and I'm having a little trouble.
Essentially, once a button on a page is clicked, I'll need to run a function included in runtime.php, and add/remove some stuff from a database.
I've not had much luck so far - I can't seem to access any Perch functionality (e.g Perch constants) when accessing the function using ajax to send a POST request to /cms/addons/apps/my_app/runtime.php
.
Has anyone got any tips for running functions through AJAX like this?
There's a good example in the Twitter app:
Hi Drew,
Thanks for that - I'm not too sure what's going on with that file but I'm using the
realpath
code to include my runtime.php file now.The way that this function is currently working is:
User clicks button on front-end of website.
AJAX Request to
/perch/addons/apps/my_app/user_interaction.php
.This file runs a function that's contained within
runtime.php
, which is included viarealpath()
.My Class files are called inside
runtime.php
. However, when I try to run this process through, I get a 500 Error, detailed below,PHP Fatal error: Class 'PerchAPI_Factory' not found
.Any ideas on this one?
Are you including the Perch runtime, or your app's? You need the central Perch runtime.
I'm including my app's
runtime.php
- I figured I probably needed to include some kind of Perch core file but when I tried to useinclude('../../../core/inc/api.php');
in myruntime.php
yesterday, it didn't work and indicated the I wasn't able to access that file due to a permissions error (presumably because I wasn't logged in to Perch?).I've updated my app's
runtime.php
to start withinclude_once($_SERVER['DOCUMENT_ROOT'].'/perch/runtime.php');
, as just usinginclude
threw the "Included more than once" error.Currently, I've got an issue with my database statements, looks like my connection is failing - but I don't think this is a Perch issue.
Thanks for all the help here, Drew!
Include the
/perch/runtime.php
file. You don't need to include anything else - it's then done for you.