문제

In one of my form type, I am generating a select widget for a given entity (Symfony 2.4 + Propel 1.7) , I'd like to change the value (for the select widget options) for the slug column not the primary key which is a basic auto-increment. I'd like to avoid using a choice type and populate the data by hand (+having to create a corresponding data transformer to get the entity). What is the best way to achieve that?

I'd like:

<!-- type1 is the slug column of the entity -->
<option value="type1">Type 1</option> 

Instead of:

<option value="1">Type 1</option>
도움이 되었습니까?

해결책

if you look a the enitytype, you'll notice that it extends the doctrinetype. in the doctrinetype you'll see a setDefaultOptions method where it sets the choices. basically you'd need to extend the entitytype and override the setDefaultOptions method that is originally provided by the doctrineType.

honestly though, it's a bit easier to just use a choice field + datatransformer in my opinion.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top