New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Access Joomla 4 framework from external php file #34586
Comments
Check the include directory, you need to load one more file: // this file is in a subfolder 'scripts' under the main joomla folder
define('JPATH_BASE', realpath(dirname(FILE) . '/..'));
require_once JPATH_BASE . '/includes/defines.php';
require_once JPATH_BASE . '/includes/framework.php';
require_once JPATH_BASE . '/includes/app.php'; |
sorry, not working define('_JEXEC', 1); require_once JPATH_BASE . '/includes/defines.php'; use Joomla\CMS\Factory; This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/34586. |
This comment was marked as abuse.
This comment was marked as abuse.
Phil, you are probably right, but i have been seeking this answer and have not found it. Until now. Thank you for your reply. I will close this now. |
Unfortunately something goes wrong with this method. While the application is loaded successfully, if you try to JRoute::_() something right below the code provided by @PhilETaylor, the site breaks.
This causes a
If you call In my case, I need to load the framework in order to use ajax from within a module extension, without introducing a whole component, just to load a few things from the database. Any insight would be really appreciated. |
Just found a joomla.stackexchange.com post that solves it. I didn't delete my comments, because I think this information is useful, as this issue appears very high on Google when someone searches to load Joomla 4 from an external php file. The solution is to register extension namespaces, after setting the application as global app.
Source: https://joomla.stackexchange.com/questions/32145/joomla-4-error-when-i-use-getarticleroute |
Steps to reproduce the issue
create php file to include joomla framework. works in J3
define('_JEXEC', 1);
// this file is in a subfolder 'scripts' under the main joomla folder
define('JPATH_BASE', realpath(dirname(FILE) . '/..'));
require_once JPATH_BASE . '/includes/defines.php';
require_once JPATH_BASE . '/includes/framework.php';
// instantiate application
$app = JFactory::getApplication('site');
Expected result
framework loaded, able to use it
Actual result
framework not loaded
System information (as much as possible)
J4 RC3
Additional comments
I am aware of jfactory, to be changed to factory, and use PHP namespaces. but even then i cannot get the J4 framework loaded in external page.
The text was updated successfully, but these errors were encountered: