【问题标题】:What's the `{$smarty.server.PHP_SELF}?action=bulkdomain` means in smarty template?smarty 模板中的 `{$smarty.server.PHP_SELF}?action=bulkdomain` 是什么意思?
【发布时间】:2018-07-20 03:18:08
【问题描述】:

我正在阅读一个smarty项目代码,有一个.tpl文件,里面有一个表格,它的动作是{$smarty.server.PHP_SELF}?action=bulkdomain

<form method="post" action="{$smarty.server.PHP_SELF}?action=bulkdomain">
...

这是什么意思?

意思是把这个请求提交到.tpl对应的.php文件吗? 但是.php 文件的功能怎么样?因为 php 代码是封闭源代码,我无法得到它。


EDIT-01

我的意思是,在模板中,使用action="{$smarty.server.PHP_SELF}?action=bulkdomain" 来分配请求方法。

请求方法应该在模板对应的php文件中怎么样?

应该这样吗?

<?php

function bulkdomain($params)
{
    ...
}

EDIT-02

在当前运行的php文件中:

<?php

require($_SERVER['DOCUMENT_ROOT'] . '/smartyHeader.php');
$smarty->registerPlugin('block' ,'hsp', 'test1');

$smarty->assign('foo', 'Foo');

$smarty->display('php/test.tpl');

如果有提交数据,我会不会在php文件中这样写代码?

<?php

require($_SERVER['DOCUMENT_ROOT'] . '/smartyHeader.php');
$smarty->registerPlugin('block' ,'hsp', 'test1');

$smarty->assign('foo', 'Foo');

$smarty->display('php/test.tpl');

// accept the code
$action =$_GET['action']

我是否接受上面写代码之类的动作?

【问题讨论】:

  • @Ghost 你好,朋友,你能看看我的edit-01吗?
  • 在表单的接收端,就像任何普通的get变量一样对待它
  • 我不明白。
  • 由于你的表单提交到当前的php本身,只要像任何get变量一样获取get变量的值,$_GET['action'],然后你会在其中得到bulkdomain

标签: php smarty


【解决方案1】:

$smarty.server.PHP_SELF$_SERVER['PHP_SELF'] 变量相同 - 表示当前运行的 PHP 文件的名称。

如果您想处理具有action="{$smarty.server.PHP_SELF}?action=bulkdomain" 的表单,您可以检查是否存在带有键“action”和值“bulkdomain”的全局$_GET 变量,例如:

if(isset($_GET['action']) && $_GET['action']=='bulkdomain') {
    // do smt
}

【讨论】:

  • 见我的 EDIT-02 兄弟。
  • @qg_java_17137 您应该将代码 before 显示页面 ($smarty-&gt;display('php/test.tpl');) 然后您将能够使用 header() 函数进行重定向,例如防止双重发送表格。
猜你喜欢
  • 2011-09-25
  • 2010-09-29
  • 2012-07-26
  • 2022-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-21
相关资源
最近更新 更多