Timeline for Best way to include helper class in sub-controller : require_once or JLoader
Current License: CC BY-SA 3.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 5, 2016 at 7:23 | history | edited | Rene Korss | CC BY-SA 3.0 |
register changes
|
| Feb 4, 2016 at 23:22 | comment | added | Michael |
Just to add to this, JLoader::register() actually registers the class to the autoloader using a given path. So later when you want to use the class you don't need a second import statement of any kind, PHP will load it automagically through the autoloading mechanisms of JLoader after that initial call to the register method.
|
|
| Feb 3, 2016 at 11:05 | vote | accept | Liz. | ||
| Feb 3, 2016 at 11:05 | comment | added | Liz. |
perfect! it worked :) I thought the 1st parameter is the classname . But realized now it must be filename. Thank you Rene
|
|
| Feb 3, 2016 at 11:00 | history | edited | Rene Korss | CC BY-SA 3.0 |
added 61 characters in body
|
| Feb 3, 2016 at 10:59 | comment | added | Rene Korss |
You file should be named TestHelper.php.
|
|
| Feb 3, 2016 at 9:43 | comment | added | Liz. |
no it was with php. JLoader::import('TestHelper',JPATH_COMPONENT.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'test.php'); But I also tried without .php. Still it doen't work
|
|
| Feb 3, 2016 at 9:34 | comment | added | Rene Korss |
Is your /path/to without .php? Path has to be absolute. So in your case JLoader::import('TestHelper', JPATH_COMPONENT.DIRECTORY_SEPARATOR.'helpers');
|
|
| Feb 3, 2016 at 9:32 | comment | added | Liz. |
Thank you for a very nice explanation. But I would need your help a little further. I used JLoader::import('TestHelper','/path/to/test.php'); but it gives me an error 'TestHelper class not found' . I did the following after importing the helper file: TestHelper::getTestfunction() . But it does not work
|
|
| Feb 3, 2016 at 8:22 | history | edited | Rene Korss | CC BY-SA 3.0 |
dot notation
|
| Feb 3, 2016 at 8:08 | history | answered | Rene Korss | CC BY-SA 3.0 |