【发布时间】:2015-06-07 04:48:19
【问题描述】:
一周以来,我一直在使用 Smarty 模板引擎,我发现它非常酷,因为它的应用程序逻辑和设计分离。我现在的问题是如何使用 smarty 做一个header('Location: somepage.php');?我知道我可以在我的 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">×</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">×</a>
</div>
{/if}
{/if}
</div>
</div
我使用 zurb-foundation 作为我的 css 框架。如您所见,我正在使用<?php header('Location: somepage.php'); ?>,这不适合smarty。有没有办法在 smarty 中做到这一点?
【问题讨论】:
-
我认为将
header重定向放在业务逻辑类中而不是视图是一个好习惯。 -
我不明白你为什么要在 tpl 文件中这样做。不仅破坏了您喜欢的酷逻辑和设计分离,而且是不好的做法,并且大多数时候可能会产生“标头已发送”错误。在处理模板之前在php中检查$_GET['success']有什么问题?