您可以在此处找到可用的选项sfWidgetFormDoctrineChoice
* model: The model class (required)
* add_empty: Whether to add a first empty value or not (false by default)
If the option is not a Boolean, the value will be used as the text value
* method: The method to use to display object values (__toString by default)
* key_method: The method to use to display the object keys (getPrimaryKey by default)
* order_by: An array composed of two fields:
* The column to order by the results (must be in the PhpName format)
* asc or desc
* query: A query to use when retrieving objects
* multiple: true if the select tag must allow multiple selections
* table_method: A method to return either a query, collection or single object
您可以使用如下order_by
选项:...->setOption('order_by', array('some_field', 'asc'))
.
更新:
如果您想按多个字段排序,您可以编写自定义查询并向其添加多个 order by,然后使用query
ortable_method
选项而不是order_by
.
例如(您应该将查询写入表类):
$query = Doctrine_Core::getTable('UserTable')->createQuery('u')->orderBy('u.last_name asc, u.first_name asc');
$this->getWidget('user_id')->setOption('query', $query);
// if you add some where condition to the query
// don't forget to set it to the validator as well
$this->getValidator('user_id')->setOption('query', $query);