开发者

How to sort a form field values through generator file using symfony?

how are you all guys?

I want to sort(in ascending or descending order) a form fields through generator.yml in symfony. I mean I have 2 tables Events and Members. Relation between these two tables are many to many. What I want is that when I go to add/edit an event, members list should be sorted b开发者_如何学Goy their names.

I tried to use:

config:
      actions: ~
      fields:
        title:           { help: Title of the event ,label: Event Name *}
        event_datetime:  { help: Set the date and time of event ,label: Date time *}
        details:   { help: Details related to event ,label: Details *}
        venue_id:           { help: Select venue }
        is_visible:   { help: Select is visible or not}
        members_list:           { help: List of members }
        slug: { help: User Friendly URL,label: User Friendly URL }
      sort: [mmebers_list, asc]

But it does not work successfully. any suggestion please?

Thanks


Try Adding this to your schema.yml

Member:
  actAs:
    Timestampable:
    Sluggable:
      unique: true
      fields: [name]
      canUpdate: true
  options:
    orderBy: name ASC

This will sort all the members lists globally in your application


I had a similar problem, but I use sfGuardUser plugin and I don't want to change their schema. I had to change action files and add:

public function executeNew(sfWebRequest $request)
{
    parent::executeNew($request);
    $sql = Doctrine_Query::create()->from('sfGuardUser u')->innerJoin("u.Profile p")->where('u.is_super_admin = ?',false)->orderBy('p.lastname');
    $this->form->getWidget('user_id')->setOption('query',$sql);
}

You need to pass query which symfony use to get data to field.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜