3

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!

1
  • Try to write module or plugin. Commented Jun 5, 2013 at 4:43

2 Answers 2

9

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

Sign up to request clarification or add additional context in comments.

Comments

1

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 :-)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.