1
votes

I want to include an external php script or modx snippet to the index.php but it causes the blank screen instead (and no document parser errors). Probably the problem is that this script i want to include contains starting session functions and set_include_path function that might somehow conflict with Modx parser.. I tried to use the Modx API but it doesn't seem to work. I use Modx 0.9.2.6 yet.. How can I overcome the issue? My script checks the session and database if the user is logged-in on the site (logging system is not modx-based) and then prints the menu depends on the user privileges...

This is what I put in the beginning of the index page template: [[modx_api_supernav]]

The code of the snippet modx_api_supernav:

<?php
$path = dirname(__FILE__).'/';
include_once($path.'modxapi.php'); //last release of Modx API file located in the root
$modx = new MODxAPI();
$modx->connect();
$modx->startSession();
$modx->runSnippet('supernav'); //snippet that contains external Zend Framework code
?>
2
are you actually changing the index.php? if so, that's not a good idea. "I tried to use the Modx API but it doesn't seem to work" the API is fine, I'd say you're probably not putting the right code in it, in which case either spend more time with the docs or show some code.Daniel
Thanks! Please look I have updated the question!moogeek

2 Answers

1
votes

If you are including [[modx_api_supernav]] in one of your MODx chunks or templates, then you really don't need all the code in your snippet.

Try the following, which works correctly if MODx is already running (as it is when calling a snippet using the [[]] syntax

<?php
$modx->runSnippet('supernav'); //snippet that contains external Zend Framework code
?>

If your supernav snippet containing external code tries to create a new session, you may end up with some very strange results.

0
votes

As PeterB says, you can just call your snippet by either $modx->runSnippet() or by including it in your content, template or chunk.

You do not need to check wether a user does or does not have access to a certain page because modx takes care of that for you.

Daniel is right, you should read more of the -pretty thorough- documentation. You should also take a look into the source of some other snippets to get you going.

AND you should really check out the WayFinder snippet (and visit www.muddydogpaws.com -> development)