在 Modx 中启动会话来运行外部 php 文件或片段?
我想将外部 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在 MODx 块或模板之一中包含
[[modx_api_supernav]]
,那么您实际上不需要代码片段中的所有代码。请尝试以下操作,如果 MODx 已在运行(就像使用
[[]]
语法调用代码片段时的情况一样,该方法可以正常工作如果包含外部代码的超级导航代码片段尝试创建新会话,您可以最终得到一些非常奇怪的结果。
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
[[]]
syntaxIf your supernav snippet containing external code tries to create a new session, you may end up with some very strange results.
正如 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)