具有多个条件的语句[symfony2]

时间:2016-10-19 10:51:03

标签: php symfony doctrine-orm twig

我的表verified中有一个名为user的实体。我想验证null是否显示[您可以上传您的申请],如果已经过验证=2以显示此[您的申请正在处理中],如果已经过验证=3您的申请已经已经过验证。

但是现在,如果已经过验证=3正在显示已验证=2.

的消息

这就是我所做的:

 {% if entity.verified is empty %}

<p>
you can upload your application
</p>

{% elseif entity.verified|length !=2 %}

<p>
your application is in process
</p>

{% elseif entity.verified|length !=3 %}

<p>
your application has been verified
</p>
 {% endif %}

user.php的

/**
 *
 * @ORM\Column(name="verified", type="decimal", options={"default" : 0}, nullable=true)
 */
protected $verified;

/**
 * Set verified
 *
 * @param string $verified
 * @return User
 */
public function setVerified($verified)
{
    $this->verified = $verified;

    return $this;
}

/**
 * Get verified
 *
 * @return string 
 */
public function getVerified()
{
    return $this->verified;
}

1 个答案:

答案 0 :(得分:1)

您不需要使用长度过滤器(该过滤器的范围用于计算数组元素,集合等),所以请尝试简单:

{% if entity.verified is empty %}    
    <p>you can upload your application</p>
{% elseif entity.verified == 2 %}
    <p>your application is in process</p>
{% elseif entity.verified == 3 %}
    <p>your application has been verified</p>
{% endif %}

反转条件。

希望这个帮助