开发者

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

开发者 https://www.devze.com 2023-03-01 13:53 出处:网络
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

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

精彩评论

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