Reputation: 33
I have few PHP classes and files that I want to include in Joomla so that I can call those classes. I tried doing require_once config.php
to include a PHP file
which also includes all the classes that I would want to use in Joomla.
But each time I execute the page I receive the error below:
Fatal error: Class 'SomeClassName' not found
is there any other way to include external PHP classes or files in Joomla?
Thanks in advance!
Upvotes: 3
Views: 4223
Reputation: 558
Please use Joomla autoloader. Is better.
<?php
// Register an adhoc class.
JLoader::register('AdhocClass', '/the/path/adhoc.php');
// Register a custom class to override as core class.
// This must be done before the core class is loaded.
JLoader::register('JDatabase', '/custom/path/database_driver.php', true);
Edit:
Load classes with autoload instead of require/include have a better performance, because PHP will only read (require access to the disk) and compile (require memory and CPU usage) if you really use your class.
To do the same with require/include you have to be sure to only use if will really use the class.
Source: http://developer.joomla.org/manual/ch01s04.html
Upvotes: 9
Reputation: 2731
require_once
should work just fine within Joomla. Make sure the class you want to use is really loaded within your file, and the file is properly referenced in the require_once
. Something is going wrong there and it has nothing to do with Joomla itself :-)
Upvotes: 1