'How to use functions that are declared in snippets in Evolution CMS (Modx) in an external PHP Script?
I am using Evolution CMS (Modx) and have several functions declared (in snippets).
Those functions I can include in Evo CMS by calling e.g. $modx->runSnippet('functions_main');
.
Now I have an external PHP script (independent from Evo CMS) and would like to use those functions there.
However, I don't know how to properly access them (from the DB) and integrate them as PHP functions.
I thought of building my own version of evalSnippet()
(Core.php) but could not get it done yet.
I would need something like include_modx_snippet('functions_main');
which reads the snippet (the defined functions) from the DB and makes them available as PHP functions.
Or I just find out how to parse the snippet content and turn it into PHP functions.
Solution 1:[1]
You can do this by first initialising Modx and then running your snippet like you would normally:
// Modx init
require_once 'config.core.php';
require_once MODX_CORE_PATH.'model/modx/modx.class.php';
$modx = new modX();
$modx->initialize('mgr');
// Run snippet
$modx->runSnippet('functions_main');
// Run your functions here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Bram Verstraten |