Php Smarty头位置

Php Smarty头位置,php,smarty,smarty3,Php,Smarty,Smarty3,一周来,我一直在使用Smarty模板引擎,我发现它非常酷,因为它的应用程序逻辑和设计分离。我现在的问题是如何做标题('Location:somepage.php')使用smarty?我知道我可以在我的php页面中这样做,但我正在我的tpl文件中这样做。这就是我的代码 <div class="row"> <div class="large-4 columns"> {if isset($smarty.get.success) or !empty($smarty.get.

一周来,我一直在使用Smarty模板引擎,我发现它非常酷,因为它的应用程序逻辑和设计分离。我现在的问题是如何做
标题('Location:somepage.php')使用smarty?我知道我可以在我的php页面中这样做,但我正在我的
tpl
文件中这样做。这就是我的代码

<div class="row">
   <div class="large-4 columns">
{if isset($smarty.get.success) or !empty($smarty.get.success)}
{if ($smarty.get.success eq '')}
<div data-alert class="alert-box warning radius">
  Warning: No value found.
  <a href="#" class="close">&times;</a>
</div>
{else}
      <div data-alert class="alert-box success radius">
      {if ($smarty.get.success eq 'updatecontact')} 
      Contact successfully updated.
      {elseif ($smarty.get.success eq 'addcontact')} 
      Contact successfully added.
      {else}
      <?php header('Location: somepage.php'); ?>
      {/if}
      <a href="#" class="close">&times;</a>
      </div>
{/if}
{/if}
   </div>
</div

{如果设置为($smarty.get.success)或!为空($smarty.get.success)}
{if($smarty.get.success eq“”)}
警告:找不到值。
{else}
{if($smarty.get.success eq'updatecontact')}
联系人已成功更新。
{elseif($smarty.get.success eq'addcontact')}
联系人已成功添加。
{else}
{/if}
{/if}
{/if}

将代码放入
{php}

{php} header ('Location: somepage.php'); {/php}
使用javascript执行此操作:

<script>
window.location = 'somepage.php';
</script>

window.location='somepage.php';

我也在使用这个。。但如果可能的话,我实际上不想在我的php页面中使用php标记:这不是。这是smarty自己的php标记。您必须让smarty知道您打算让它运行PHP代码,对吗?阅读更多信息:是的,先生,我使用新的SmartyBC()启用了此功能;而不是新的Smarty();只有无论如何,谢谢。我认为在业务逻辑类中放置
标题
重定向将是一个很好的实践,而不是视图。我不明白为什么要在tpl文件中这样做。这不仅打破了您喜欢的冷静的逻辑和设计分离,而且是一种糟糕的做法,在大多数情况下,它可能会产生一个“Headers ready-sent”错误。在处理模板之前,在php中检查$_GET['success']有什么问题?