【问题标题】:Some Entity Values going to set as Null by default. while Updation Symfony2默认情况下,某些实体值将设置为 Null。同时更新 Symfony2
【发布时间】:2016-02-05 07:15:53
【问题描述】:

您好,我有以下情况:

//User Entity:
firstname: S
LastName: R
email : ss@gm.com
Status: "Active"
//User Profile entity:
profilePic: 
favoritemovies: 
Hobbies:

因此,在更新用户配置文件实体时,我只呈现两个实体的以下字段:

firstname:
LastName:
email:
profilePic:
favoritemovies:
Hobbies: 

所以在这里我不希望用户更新他的状态字段,所以我没有在更新 ProfileForm 时呈现它。现在当我更新 ProfileForm 时,“用户实体”的“状态”字段也设置为 NULL 默认值。谁能指导我在这方面缺少什么。

我正在使用 symfony 2.6 和 MySql:

提前致谢。

【问题讨论】:

    标签: php mysql symfony


    【解决方案1】:

    您不应该将此字段添加到您的例如。 ProfileType.php 类,则不包含的字段不应该更新。

    你的实体设置器的另一种方式是你可以这样设置状态:

    /**
     * Set status
     *
     * @param string $status
     * @return User
     */
    public function setStatus($status)
    {
        if (!is_null($status)) {
            $this->status = $status;
        }
    
        return $this;
    }
    

    那么就不可能将空数据保存到状态属性。

    【讨论】:

      猜你喜欢
      • 2014-04-30
      • 1970-01-01
      • 2013-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-07
      • 1970-01-01
      相关资源
      最近更新 更多