Possible to call Datatables Editor PHP library if it's located outside the project folder?

Possible to call Datatables Editor PHP library if it's located outside the project folder?

Taylor74Taylor74 Posts: 7Questions: 2Answers: 0

Hi,

With the goal of using Editor in different applications on the same server, would it be possible to place one instance of the Editor PHP library outside of the project(s) root folder? After attempting to do this, I was having issues after the "DataTables.php" include due to the following line (being that the library is now outside of the folder it is being included from):

require( dirname(__FILE__).'/Bootstrap.php' );

I was just curious if there might be a way to accomplish this without altering the lib files? If not, my understanding would be then that for each application Editor is to be used in, a copy of that "lib" folder from the PHP Editor library would need to be located inside of the project's root folder.

Thank you,
Taylor

Answers

  • allanallan Posts: 63,210Questions: 1Answers: 10,415 Site admin

    Yes you could do:

    require( '/absolute/path/to/Bootstrap.php' );
    

    You will have to check if your server's security allows that though. Normally web-servers are run to not allow files outside of the web root to be included for security reasons.

    Allan

  • Taylor74Taylor74 Posts: 7Questions: 2Answers: 0

    Hi Allan,

    Thanks for the response. I am not actually putting the Editor library outside of the web root, sorry that I was unclear about that.

    So say I have 2 applications, locations are "/var/www/project1/" and "/var/www/project2/". The Editor PHP library location is "/var/www/include_libs/Editor-PHP-1.9.2/". This is how the require path issues arise (because the Editor library is outside of both project folders).

    As you suggested above, I have edited the following files to use absolute paths rather than "dirname(__FILE__)" or "__DIR__"
     

    Editor-PHP-1.9.2/lib/DataTables.php:

    //replace 
    require( dirname(__FILE__).'/Bootstrap.php' );
    //with
    require( '/var/www/include_libs/Editor-PHP-1.9.2/lib/Bootstrap.php' );
    

    Editor-PHP-1.9.2/lib/Bootstrap.php:

    //replace
    require( dirname(__FILE__).'/'.$path.$className.'.php' );
    //with
    require( '/var/www/include_libs/Editor-PHP-1.9.2/lib/'.$path.$className.'.php' );
    
    //note, I have defined my own $sql_details config variable within each project folder
    

    Editor-PHP-1.9.2/lib/Vendor/Htmlaw.php:

    //replace
    require_once __DIR__.'/htmLawed/htmLawed.php';
    //with
    require_once '/var/www/include_libs/Editor-PHP-1.9.2/lib/Vendor/htmLawed/htmLawed.php';
    

    After making these updates in the Editor library, everything SEEMS to be working properly, though I obviously am not able to test all possible Editor functionality. Please let me know if you feel these changes to the Editor library may cause any issues that I might be unaware of.

    Thanks so much for your help,
    Taylor

  • allanallan Posts: 63,210Questions: 1Answers: 10,415 Site admin

    Hi Taylor,

    I don't think you should actually need to make any changes to the library files - they should all work with relative paths compared to each other.

    The only one you'd need to modify is your own include, which in this case would be:

    require( '/var/www/include_libs/Editor-PHP-1.9.2/Bootstrap.php' );
    

    Allan

  • allanallan Posts: 63,210Questions: 1Answers: 10,415 Site admin

    Oh - I would point out you might need to be careful with this approach since it would end up sharing the database connection credentials between your projects! You might indeed want to make a little change to account for that, or you can define $sql_details before including the Bootstrap.php file.

    Allan

  • Taylor74Taylor74 Posts: 7Questions: 2Answers: 0

    Hi Allan,

    Thanks for the replies. It turns out the original include works just fine without the need to alter any of the Editor library files:

    include( '/absolute/path/to/Datables.php' );
    

    When I had moved the Editor library from it's original location it seems the server had actually cached (or something like it) the old location of the library and kept looking there for the files (I moved the library from VS Code using an SSH connection to the server, so this may have been the culprit). In any case, the ultimate solution was to copy a fresh version of the library to where I wanted it to be. Worked perfectly after that.

    I appreciate the suggestions as they did finally lead me to finding the actual cause of the issue, you gave me some other good things to keep in mind as well.

    Thank you!
    Taylor

This discussion has been closed.