In the API section of the MODx Wiki it says:
http://wiki.modxcms.com/index.php/API:DocumentParser
"To see what the $modx variable contains when your script is run, try putting this in to your script:"
<?php
return print_r($modx,true);
?>
Whenever I try this I get the following error:
« MODx Parse Error »
MODx encountered the following error while attempting to parse the requested resource:
« PHP Parse Error »
PHP error debug
Error: Unknown(assets/templates/mytemplate/file.html): failed to open stream: No such file or directory
Error type/ Nr.: Warning - 2
File: /var/www/vhosts/newheights.com/subdomains/sbox/httpdocs/manager/includes/document.parser.class.inc.php(748) : eval()'d code
Line: 11
Parser timing
MySQL: 0.1012 s (121 Requests)
PHP: 1.3661 s
Total: 1.4673 s
I have tried several tweaks and can’t seem to get it to output the $modx array.
Any ideas?
"Regret for the things we did can be tempered by time; it is regret for the things we did not do that is inconsolable."
-- Sydney Harris
-
☆ A M B ☆
- 24,524 Posts
That error means that there is a snippet or a plugin trying to access that file on line 11 of its code.
Quote from: sottwell at Apr 08, 2007, 05:12 AM
That error means that there is a snippet or a plugin trying to access that file on line 11 of its code.
In my snippet I have the following:
<?php
return print_r($modx,true);
?>
Line 11: of [tt]document.parser.class.inc.php[/tt] is the last line in this block:
<?php
/**
* MODx Document Parser
* Function: This class contains the main document parsing functions
*
*/
class DocumentParser {
var $db; // db object
var $event, $Event; // event object
var $pluginEvent;
I suppose my question is: a) am I doing something wrong? b) is the code in the wiki wrong? c) is there some other problem?
The snippet only contains one line of code so I thought maybe there was a typo on the wiki. So far, I have not had a chance to work with the MODx API so this is all foreign to me but I would think this should be pretty strait forward.
I am using MODx 9.5.
"Regret for the things we did can be tempered by time; it is regret for the things we did not do that is inconsolable."
-- Sydney Harris
-
☆ A M B ☆
- 24,524 Posts
That is not referring to line 11 of document.parser.class.inc.php; notice it says it’s in the eval()’d code at line 11. That means that it is running something through the eval() function, and that something has the file access on its line 11. So there is another snippet or plugin causing the error.
That is odd since it only happens when I try to access the $modx array. I can run it through a count() function and it gives me "1" but if I try to run it through any function that trys to access its values I get the same error ([tt]array_rand($modx),[/tt] for example). As soon as I do not try to access the array everything works fine. Am I missing something here? How can accessing that array be causing a problem in another snippet?
"Regret for the things we did can be tempered by time; it is regret for the things we did not do that is inconsolable."
-- Sydney Harris
Ok, so to avoid problems with other snippets I set the template to blank so that there was not any other snippets being run and now I get this error:
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 991070 bytes) in /var/www/vhosts/newheights.com/subdomains/sbox/httpdocs/manager/includes/document.parser.class.inc.php on line 841
Each time I refresh both the allowed memory size and the tried to allocate size change to totally different numbers (though after several refreshes i do notice that they seem to only refreshing between 3-4 different numbers for each).
Bleh, I have this itching feeling this is something stupid...
"Regret for the things we did can be tempered by time; it is regret for the things we did not do that is inconsolable."
-- Sydney Harris
-
☆ A M B ☆
- 24,524 Posts
Yes, I’m getting weird errors when trying this myself. Looks like it’s putting it in some kind of loop.
Interesting. I’m also getting an out of memory error trying this in a fresh install of 0.9.6 RC2 (rev 2446/Linux/Apache/PHP 4.3.1.0). I’ve done this in previous versions with no problem, so this seems to be a new issue.
Good, well at least I am not crazy.
In the meantime, is there any other way to get a listing of the values in that array?
I am starting to poke around with snippet development and I wanted to see what I have to work with.
"Regret for the things we did can be tempered by time; it is regret for the things we did not do that is inconsolable."
-- Sydney Harris
-
MODX Staff
- 10,725 Posts
First, $modx is not an array; it is an object.
Second, this is going to be problematic because it exposes tags within cached content stored on the object in the output that has already been processed. When processed again through the parser, this causes a loop effect which will likely cause an out of memory or some other critical error before the output can ever be sent back.
It is better to print_r specific object variables from the $modx object to find what you are looking for. For instance, return ’<pre>’ . print_r($modx->config, 1) . ’</pre>’ will print the config array, or ’<pre>’ . print_r($modx->aliasListing, 1) . ’</pre>’ will print the listing of document alias information. But beware of outputting $modx->pluginCache, $modx->chuckCache, or other similar arrays that might return content that would be parsed again.