I think I’m facing several problems in one place here, but the $modx is in the middle of them.
I just can’t replace the PATH.
The code in the Elements>Snippet is only this:
<?php
include_once $modx->getOption('core_path').'components/myProject/snippet.php';
Then the snippet only retrieve all the [[!call?param=`var`]] variables from the page, making them as a configuration array, then passing them to the class.
The classes come from different files.
<?php
include_once MODX_BASE_PATH . 'myProject' . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'parent.class.php';
include_once MODX_BASE_PATH . 'myProject' . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'child.class.php';
$myObject = new myChildClass();
$output = $myObject->childFunction($configArray);
echo $output;
<?php
class myParentClass {
public $configArray;
// as your suggestion
public function __construct(modX &$modx) {
$this->modx =& $modx;
}
public function parentFunction($buffer, $configArray) {
// don't mind about the $configArray, it's used elsewhere
$buffer = str_replace(SOME_PATH . 'index.php', MODX_SITE_URL . '/index.php?id=' . $modx->resource->get('id') , $buffer);
return $buffer;
}
}
<?php
class myChildClass extends myParentClass {
public $configArray;
public function childFunction($configArray) {
ob_start();
require(SOME_PATH . 'index.php');
$buffer = ob_get_contents();
ob_end_clean();
// buffering the output
$output = parent::parentFunction($buffer, $configArray);
return $output;
}
}