bug? custom page

Please report bugs and any annoyances here. Kindly include all possible details: steps to reproduce, expected result, actual result, screenshots, ... etc.
Post Reply
grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

bug? custom page

Post by grimblefritz » 2016-07-14 00:06

AppGini 5.51

I'm basing an ajax call on the technique give in the Udemy course. The code I have in the ajax php file is;

Code: Select all

<?php

        $currDir = dirname(__FILE__) . '/..';
        include("$currDir/defaultLang.php");
        include("$currDir/language.php");
        include("$currDir/lib.php");

        /* grant access to all users with access to material table */

...
With this script in the hooks folder, I get an error 500. Tracing through, the error occurs in loading lib.php

If I move the script into the application folder (up, out of hooks) and change the $currDir assignment:

Code: Select all

        $currDir = dirname(__FILE__);
then the ajax call/script work perfectly.

I'd say this is a bug, right? Ajax scripts should be able to exec from the hooks folder (or any other folder so long as the paths are adjusted properly.)

peebee
AppGini Super Hero
AppGini Super Hero
Posts: 352
Joined: 2013-03-21 04:37

Re: bug? custom page

Post by peebee » 2016-07-14 03:45

My understanding is that any scripts within the hooks folder don't require the $currDir or include commands as all Appgini functions are already loaded by the time hooks are called. They are only required for external pages.

Did you try your script in the hooks folder without the additional php commands?

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: bug? custom page

Post by grimblefritz » 2016-07-14 12:45

peebee,

That is correct for actual hooks - that is, things called from within the AppGini code as subprocesses.

In the case of ajax, the javascript side is running in the AG context. It has access to the full AG environment.

The php ajax provider, however, is not. It is a stand-alone script running 100% in its own space. In order to have access to the AG functions, it is necessary to load the AG language and lib files. This is true of any stand-alone custom script.

See http://bigprof.com/appgini/help/advance ... cess-pages

While that's titled for limited access pages, it's description is a little too confining. It applies to all custom pages, including ajax provider scripts. In fact, it is how Ahmad does it in his Udemy course example, citing this exact web page.

When I try it, however, it fails - unless I move the ajax provider script up out of hooks and into the app directory. In the hooks folder, it fails while loading lib.php.

To me, that suggests there's something in lib.php that is dependent on the runtime directory being the AG app directory. If the runtime directory is app/hooks, it breaks. I think the Udemy course was using 5.40, so maybe something changed in lib.php in 5.51.

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: bug? custom page [SOLVED]

Post by grimblefritz » 2016-07-14 13:33

LOL @ self

After writing the previous, I got to thinking: Ahmad has probably done this a zillion times and wouldn't steer us wrong. So... what else might have changed (ie, what did "I" do wrong?)

After browsing lib.php, I discovered it is what loads hooks/__global.php

Guess who has several things added in __global.php? Yeah, me. So I went to investigate there (even though all my __global.php stuff has been working flawlessly... until i started doing ajax stuff.)

Lessons for everyone:

1. If you're doing a lot with hooks... It's probably not AppGini that's the problem.

2. If you're using __global.php, don't use paths with a literal "hooks/..." in them.

From a normal AG page, the runtime directory will be the AG appdir, so hook files will be in "hooks/..." - relative to appdir.

From a custom page, such as a ajax provider, the runtime directory will be the directory where the script is found. In this case, hooks. In effect, appdir/hooks becomes the new appdir.

So, if you have, in __global.php, the line:

Code: Select all

include("hooks/myfile.php");
then in a normal AG page it will load. The file path is:

Code: Select all

appdir/hooks/myfile.php
Life is good.

On the other hand, if you're calling a custom/ajax page in hooks, you're using the URL:

Code: Select all

http://domain.com/hooks/myfile.php
The runtime directory will not be appdir, but rather appdir/hooks (or some other path, if not putting custom pages in hooks.) So in __global.php your include path is expanded to become:

Code: Select all

hooks/hooks/myfile.php
Which doesn't exist, and... crash!

SOLUTION

Code: Select all

include(dirname(__FILE__).'/myfile.php');

Post Reply