Need Help on How to Integrate a PHP Script With a Dashboard Single Page

Permalink
I am working on a free add-on for the marketplace that will utilize a php script to show some simple statistics.

I already know how to create the single page, and install the add-on. I am having trouble figuring out exactly how to integrate a php script.

I have the singe page itself written up, but for it to display, it needs to include the script itself.

I have looked at other add-ons to see how something like this is done, but I'm lost. What are the differences between the "tools", "helpers", "libraries", and "models" directories that I have seen in other packages? I don't understand fully how that stuff works.

I tried adding the script to a "models" directory, and at one point, the script seemed to work, aside from a bunch of errors that were visible on the page.

Now, I am seeing the following errors:
Warning: include(/models/visitorsonline.php) [function.include]: failed to open stream: No such file or directory in /home/gcloca5/public_html/c5/packages/visitors_online/single_pages/dashboard/reports/visitors_online.php on line 7
Warning: include() [function.include]: Failed opening '/models/visitorsonline.php' for inclusion (include_path='/home/gcloca5/public_html/c5/libraries/3rdparty:/home/gcloca5/public_html/c5/concrete/config/../libraries/3rdparty:.:/usr/lib/php:/usr/local/lib/php:/home/gcloca5/php') in /home/gcloca5/public_html/c5/packages/visitors_online/single_pages/dashboard/reports/visitors_online.php on line 7
Fatal error: Class 'Visitorsonline' not found in /home/gcloca5/public_html/c5/packages/visitors_online/single_pages/dashboard/reports/visitors_online.php on line 8


Anyone have an idea of what I'm doing wrong?

PineCreativeLabs
 
Mainio replied on at Permalink Reply
Mainio
Have you read this:
http://www.concrete5.org/documentation/developers/system/directory-...

It basically explains what those directories are for.

The correct one for you seems to be "libraries" and if that is a third party library, that should go into "libraries/3rdparty".

Loading that library:
http://www.concrete5.org/documentation/developers/system/loading-ob...
PineCreativeLabs replied on at Permalink Reply 1 Attachment
PineCreativeLabs
Thanks for the information. However, after looking at the links, I'm still confused. I have attached my add-on of what I have so far.

Basically, the addon uses a PHP class to show how many visitors (both registered and unregistered) were online, and for how long.

It creates a dashboard single page (dashboard/reports/visitors_online), and displays this data.

Take a look at the attachment. What am I missing? How do I make this work?
Mainio replied on at Permalink Reply
Mainio
1. Put a view() method in the controller (and I'd also suggest moving some of the logic to controller, your view looks quite heavy currently). Read through this, I think it will clear some things up for you:
http://www.concrete5.org/documentation/developers/pages/mvc-approac...

2. From the looks of your /models/visitorsonline.php, that should rather be in /libraries/visitorsonline.php. Just the MVC convention, this seems to be more of a library than a model. Model is usually an object that stores data, that file also has a data storing object but it actually includes two classes in one file. Therefore, I think the proper place would be in libraries.

3. Including the script.
You currently have:
include("visitorsonline.php");


After moving it to libraries you should load it with the Loader class (the link in the previous message explains this)

4. Suggestion
That script seems to store the data in a datafile, you should probably place that in /files/ instead of the current location. That is the third parameter you pass to the class constructor (pass there DIR_FILES_UPLOADED_STANDARD constant, it contains the files dir).

I would probably consider making even own directory for that in the files dir during the add-on installation.


5. Final words
I wouldn't probably be using this script on a high traffic site because it stores the contents straight into a data file. File IO might be slower and you might experience some performance problems in the dashboard-side as that file grows large.