php 内的 Expressionengine 标签
在启用 php 解析的表达式引擎中,
如果我执行以下操作,它会起作用并且我会显示用户名。登录用户是admin。所以它回显了 admin。
<?php
$x = '{username}';
echo $x;
?>
但是,如果我执行以下操作并在 de mkdir()
函数中使用 {username} 标记,则它不起作用。创建的目录的名称将是 {username}
而不是 admin。为什么会出现这种情况。
<?php
$x = '{username}';
mkdir($x);
?>
In expressionengine with php parse enabled,
if i do the following, it works and i get the username displayed. logged in user is admin. So it echos out admin.
<?php
$x = '{username}';
echo $x;
?>
However if i do the following and use the{username} tag insde mkdir()
function, then it doesn't work. The directory created will have the name {username}
instead of admin. Why is this happening.
<?php
$x = '{username}';
mkdir($x);
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我建议编写一个快速 插件 接受登录的用户名作为参数,那么您的
mkdir()
是否在插件中工作。该插件还有更多内容,但这就是它的核心内容。然后像
{exp:make_directory username="{logged_in_username}"}
那样调用它。I'd suggest writing a quick plugin that accepts the logged-in username as a parameter, then does your
mkdir()
work within the plugin.There's more to the plugin, but that's the guts of it. Then call it like
{exp:make_directory username="{logged_in_username}"}
.表达式引擎是一个模板引擎。它几乎肯定会缓冲输出然后替换它,这就是为什么它适用于 echo 而不适用于函数。
我不是 EE 方面的专家,但这样的事情可能会起作用:
关键是你需要获得 EE 的返回解释,而不是仅仅传递原始文本。
如果您无法轻松获取输出,您还可以使用
ob_start()
来捕获输出EE回归。例如:另请注意我使用
escapeshellarg()
来降低攻击风险。Expression engine is a templating engine. It almost certainly buffers output then replaces it, which is why this will work with
echo
but not functions.I'm not an expert in EE, but something like this might work:
The point is you need to get the return of EE interpreting that, rather than just passing the raw text.
You can also use
ob_start()
to capture the output if you can't easily get EE's return. For example:Note also my use of
escapeshellarg()
to reduce the risk of attack.您是否可以将其设置为在 EE 标记之前解析您的 PHP?您不仅需要设置允许 php 解析,还需要设置它发生的顺序。
http://expressionengine.com/user_guide/templates/php_templates.html
Is it possible you have it set up so your PHP is being parsed before the EE tags? Not only do you need to set to allow php parsing but what order it happens in as well.
http://expressionengine.com/user_guide/templates/php_templates.html
您可能需要在 CP 模板管理器中的模板首选项中将“PHP 解析阶段”设置为“输出”,因为 PHP 在表达式引擎呈现 ee 标记后执行。
You may need to set 'PHP Parsing Stage' to 'output' in the preferences of your template in the CP Template Manager, because then PHP executes after expression engine rendered the ee tags.