简体   繁体   中英

PHP pages in Joomla! 3.x

I'm building a Joomla! 3.3.6 website, and I want to put in it a tool that I've made. I know there are lots of plugins that lets me to write PHP or JavaScript in Joomla!'s modules, but this tool uses a dompdf library and has lots of .js and .php files, so it could be very difficult (if not impossible) to integrate it in this way.

So I need to put it in a directory and give him the same access restrictions and user controls as the rest of Joomla! website. I need to put in these pages a code that checks if the user is logged in and, in that case, takes the user's id/username. After some operations the page needs to save informations in the Joomla!'s database, in the user's table (using user's id as reference).

I've found this script that should do the job:

<?php
    define( '_JEXEC', 1 );
    define('JPATH_BASE', __DIR__);
    require_once ( JPATH_BASE .'/includes/defines.php' );
    require_once ( JPATH_BASE .'/includes/framework.php' );
    $app = JFactory::getApplication('site');
    $db = JFactory::getDbo(); 
    $user = JFactory::getUser();
    $profile = JUserHelper::getProfile($user->id);
?>

But adding

require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );

Causes the page to be loaded blank.

Is there a way to do what I need or not?

This simply means that JPATH_BASE has been not defined correctly. Blank page means there are errors on your page but you need to enable error reporting.

Try changing this:

define('JPATH_BASE', __DIR__);

to this:

define( 'JPATH_BASE', realpath(dirname(__FILE__).'/..' ));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM