Search code examples
phpdatabasemodulefatal-errorjoomla3.4

JFile not found after adding code for JFactory in custom module


I created a custom donation module where I post some form data from default.php to another php script called checkout.php. Now I have added some code to insert data into a database in checkout.php

//setup db  
$db =& JFactory::getDBO();

//create database table if needed
$createTable = "CREATE TABLE IF NOT EXISTS `#__idealdonaties` ( " . 
    "`id` int(10) NOT NULL, " . 
    "`donateur_id` varchar(40) NOT NULL, " . 
    "`naam` varchar(100) NOT NULL, " . 
    "`email` varchar(250), " . 
    "`bedrag` varchar(100) NOT NULL, " . 
    "`status` int(1) DEFAULT 0, . 
    PRIMARY KEY (`id`), KEY `donateur_id` (`donateur_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
$db->setQuery($createTable);
$db->query();

//insert data into table
$insertData = "INSERT INTO `#__idealdonaties` ( `donateur_id`, `naam`, `email`, `bedrag`, `status` ) " .
    "VALUES (`" . $brq_invoicenumber . "`, `" . $cust_name . "`, `" . $cust_email . "`, `" . $brq_amount . "`, 0)";
$db->setQuery($insertData);
$db->query();   

but got an error:

Fatal error: Class 'JFactory' not found in /home/sitesosimple/public_html/modules/mod_idealdonatie/checkout.php on line 87

Now I have fixed that error (after some searching) by adding the code:

define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../' ));  
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );

$mainframe = JFactory::getApplication('site');

But now I get a whole new error:

Fatal error: Class 'JFile' not found in /home/sitesosimple/public_html/modules/mod_roknavmenu/lib/RokNavMenu.php on line 73

For some reason the roknavmenu module can't locate the JFile Class though I changed nothing in that php file nor did I do anything with the file.php script which includes the JFile class.

I already copied a new version of file.php into the /public_html/libraries/joomla/filesystem folder. But to no avail.


Solution

  • Not sure if it's the right sollution, but it seemed to have worked. I removed the line: $mainframe = JFactory::getApplication('site');.