中號的schema.yml:如何使用symfony在管理面板中對自己的列進行排序?
News:
columns:
title:
type: string(50)
category_id:
type: integer(4)
relations:
Category:
local: category_id
foreign: category_id
type: one
Category:
columns:
category_name:
type: string(50)
generator:
class: sfDoctrineGenerator
param:
model_class: News
theme: admin
non_verbose_templates: true
with_show: false
singular: ~
plural: ~
route_prefix: news
with_doctrine_route: true
actions_base_class: sfActions
config:
actions: ~
fields: ~
list:
display: [news_id, title, category_name]
filter:
display: [news_id, title, category_id]
form: ~
edit: ~
new: ~
在news.class:
public function getCategoryName()
{
return $this->getCategories()->getCategoryName();
}
這工作,但我不能這個字段排序。我可以按id,title,category_id排序,但不能按category_name排序。我如何根據此自定義列進行排序?
非常非常非常感謝你! :) –
在您的'generator.yml'的'fields'部分,您可以定義一個字段應該被視爲真實:'category_name:{is_real:true}',因此您不必編輯模板。另外,'isValidSortColumn()'可以使用對父函數的引用,所以不需要使用實際的表名(可以改變超時)。 –