Also tried including from filesystem as suggested on that wiki page, but I get this error:
« MODx Parse Error »MODx encountered the following error while attempting to parse the requested resource:
« PHP Parse Error »
PHP error debug
Error: include() [function.include]: Failed opening ’’ for inclusion (include_path=’.;\xampp\php\pear\’)
Error type/ Nr.: Warning - 2
File: C:\path\to\modx\manager\includes\document.parser.class.inc.php(769) : eval()’d code
Line: 12
Parser timing
MySQL: 0.0075 s (3 Requests)
PHP: 0.0720 s
Total: 0.0796 s
As written there, I’ve created the file "resource.php" on filesystem, with this path:
path\to\modx\stuff\resource.php
Then I’ve created the snippet "IncludeFile":
<?php
//Check that the file is given.
if (!isset($file) || $file == "") {
return 'No file specified.';
}
//Start the buffer
ob_start();
//Include file contents
include $phpfile;
//Get contents from the buffer
$ob_contents = ob_get_contents();
//Kill/delete the buffer
ob_end_clean();
//Return contents to MODx
return $ob_contents;
?>
...and called that as:
[[IncludeFile? &file=`stuff/resource.php`]]
This generates the error as above.
By the way, I’ve changed the snippet IncludeFile with the following:
<?php
if(!isset($filename)) return;
$filepath = "stuff/";
$filetype = ".php";
$scriptfilename = $filepath.$filename.$filetype;
if(!file_exists($scriptfilename)){
return ("<strong>Error:</strong> PHP script file ".$scriptfilename." not found");
}
include($scriptfilename);
?>
..called by:
[!IncludeFile?filename=`resource`!]
...and this works.
Three questions:
- Why the code on the wiki gives me that error?
- Can I use the code I’ve written here without problems, or the one on the wiki is better?
- Does MODx manages cache correctly if I use this method? That is, whenever I change the content of resource.php, do I have to clean the cache or it’s not necessary?