在 Modx 中启动会话来运行外部 php 文件或片段?

发布于 2024-09-04 11:45:45 字数 720 浏览 8 评论 0原文

我想将外部 php 脚本或 modx 片段包含到 index.php 中,但它会导致空白屏幕(并且没有文档解析器错误)。问题可能是我想要包含的这个脚本包含 starting session 函数和 set_include_path 函数,可能会与 Modx 解析器发生冲突。我尝试使用 Modx API,但它似乎不起作用。我还使用 Modx 0.9.2.6.. 我怎样才能克服这个问题? 我的脚本检查会话和数据库,如果用户登录到站点(日志记录系统不是基于 modx),然后根据用户权限打印菜单...

这是我放在索引开头的内容页面模板:[[modx_api_supernav]]

代码段 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
?>

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
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

隔纱相望 2024-09-11 11:45:45

如果您在 MODx 块或模板之一中包含 [[modx_api_supernav]],那么您实际上不需要代码片段中的所有代码。

请尝试以下操作,如果 MODx 已在运行(就像使用 [[]] 语法调用代码片段时的情况一样,该方法可以正常工作

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

如果包含外部代码的超级导航代码片段尝试创建新会话,您可以最终得到一些非常奇怪的结果。

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.

怪我闹别瞎闹 2024-09-11 11:45:45

正如 PeterB 所说,您可以通过 $modx->runSnippet() 来调用您的代码片段,或者将其包含在您的内容、模板或块中。

您不需要检查用户是否有权访问某个页面,因为 modx 会为您处理这些问题。

丹尼尔是对的,您应该阅读更多“相当详尽的”文档。
您还应该查看其他一些代码片段的来源,以帮助您继续前进。

并且您确实应该查看 WayFinder 片段(并访问 www.muddydogpaws.com -> 开发)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文