Symfony 4 Doctrine using setter getter fuction to store different data in same field

I am working in a web application developed by PHP framework Symfony 4. I am not really familiar with Doctrine. So i need help in this case.
In existing database, there is a entity called "type". Now from one field from Form data directly saved in "type".
I need to store the data from 2 different input field, "type" and "key", from Form to "type" and store it in database, using third bracket, like this type[key]. And need to separately access the data from database.
I can not change the database, so i have to do it in this manner. Could you please tell me how to do this?
Previous code was this ~

    /**
     * @ORMColumn(type="string", length=255, nullable=true)
     * @AssertLength(
     *      min = 0,
     *      max = 255,
     *      minMessage = "ジャンルを入力して下さい。",
     *      maxMessage = "ジャンルを255文字以内に抑えて下さい。"
     * )
     */
    private $type;
 public function getType()
    {
        return $this->type;
    }

    public function setType($type)
    {
        $this->type = $type;

        return $this;
    }

Now i changed the code like the following manner ~

  public function getType()
    {
        return $this->type;
    }

    public function setType($type,$key)
    {
        $this->type = $type + [$key];

        return $this;
    }

    public function getKey()
    {
        return $this->type;
    }

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *