E
E
e-hot2015-12-01 23:27:54
symfony
e-hot, 2015-12-01 23:27:54

How to drive more than one entity parameter into one form field in Symfony 2?

Greetings. Need advice on the following situation:
1. There is a certain entity Geo, described by several parameters: city-ID, city-name, region-ID, region-name, region-ID, region-name.
2. There is a form in which a list of cities is pulled through the entity type, where property = city-name, and value = city-id.
3. I can't figure out how to make value = city-id remain as before, and property would become city-name ( area-name ), where area-name is needed only for user reference. In other words: how can property = city-name add region-name?
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis, 2015-12-02
@prototype_denis

It? symfony.com/doc/current/reference/forms/types/enti...

E
e-hot, 2015-12-02
@e-hot

Thank you all - the problem is solved quite simply! As I suggested now: in Entity we add the necessary parameter to the getter:

/**
     * Get city_name
     * @return string 
     */
    public function getCityName()
    {
        return $this->city_name . ' : ' . $this->getDistrictName();
    }

or
/**
     * Get city_name
     * @return string 
     */
    public function getCityName()
    {
        return $this->getDistrictName() . ' => ' . $this->city_name);
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question