包含多个条件的分支if语句[symfony2]


twig if statement with multiple conditions [symfony2]

在表user中有一个名为verified的实体。我想如果验证是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;
}

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

{% 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 %}

并反转条件

希望对您有所帮助