php 如何检查Smarty中是否存在变量?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7751876/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I check if a variable exists in Smarty?
提问by Dail
I'm using Smarty template engine.
我正在使用 Smarty 模板引擎。
I'm doing a simple login page. I set a variabile named errorwith a message if there are some problems, but IF NOT I get:
我正在做一个简单的登录页面。如果有一些问题,我会设置一个名为error的变量并带有一条消息,但如果没有,我会得到:
Notice: Undefined index: error
How could I check if this variable exists?
我怎么能检查这个变量是否存在?
I only do:
我只做:
{if $error}<h1>{$error}</h1>{/if}
thanks
谢谢
回答by Wesley van Opdorp
There you go!
你去吧!
{if isset($error)}
回答by Sampath Perera
This is short :) No warnings or errors.
这很短:) 没有警告或错误。
{if $error}