This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » support » symfony 1.3 and 1.4 » Drop Down Values from query
Drop Down Values from query [message #103412] Mon, 02 August 2010 13:43 Go to next message
nodoso  is currently offline nodoso
Messages: 7
Registered: July 2010
Junior Member
Hey

Have been looking on the internet but can't figure it out.

I have a drop down list which should get values from my database.
But it seems that my values are taken from the description column.
So I do the following in the code:

in FsRoleTable:
 public static function getRoleList()
  {
    $table = Doctrine_Query::Create()
      ->select('r.role')
      ->from('FsRole r')
      ->orderBy('r.id')
      ->execute();

    return $table;
  }


in FsEmployeeForm where I want to show the different roles:
$this->widgetSchema['role_id'] = new sfWidgetFormSelect(array('choices' => FsRoleTable::getRoleList()));


But I still get the values from description instead of the role column.

Any help would be appreciated.
Re: Drop Down Values from query [message #103415 is a reply to message #103412 ] Mon, 02 August 2010 14:23 Go to previous messageGo to next message
cokker  is currently offline cokker
Messages: 582
Registered: January 2007
Location: Germany
Faithful Member
Do you have overridden the toString method?

With sfWidgetFormDoctrineChoice you can configure a method to use a different Method instead of toString()

I hope my answer is not too confusing.

greets
Sven

Re: Drop Down Values from query [message #103420 is a reply to message #103412 ] Mon, 02 August 2010 15:18 Go to previous messageGo to next message
nodoso  is currently offline nodoso
Messages: 7
Registered: July 2010
Junior Member
I understand what you mean but can't figure out how to do it:

- use the toString overwrite
- use the sfWidgetFormDoctrineChoice

I tried the sfWidgetFormDoctrineChoice

So I use the function:
            $this->widgetSchema['role_id'] = new sfWidgetFormDoctrineChoice(array(
        'model' => 'FsRole',
        'method' => 'getRoleList()'
	));


Where should the method be implemented I am all lost with the many classes in symfony?

And I get this error:
Unknown record property / related component "role_list()" on "FsRole"





For more information here are my yaml classes
My employee class is:
FsEmployee:
        actAs: { Timestampable: ~ }
        columns: 
                id: { type: integer, notnull: true, autoincrement:true, primary:true }
                name: { type: string(255), notnull: true }
                birthdate: { type: date, notnull: true }
                salary: { type: integer, notnull: true }
                title: { type: string(255), notnull: true }
                shop_id: { type: integer, notnull: false }
                airport_id: { type: integer, notnull: false }
                player_id: { type: integer, notnull: true }
                role_id: { type: integer, notnull: false }
        relations:
                FsShop: { onDelete: CASCADE, local: shop_id, foreign: id }
                FsAirport: { onDelete: CASCADE, local: airport_id, foreign: id }
                FsPlayer: { onDelete: CASCADE, local: player_id, foreign: id }
                FsRole: { onDelete: CASCADE, local: role_id, foreign: id }


My Role class:
FsRole:
       columns:
              id: { type: integer, notnull: true, autoincrement:true, primary:true }
              role: { type: string(100), notnull: true }
              description: { type: string(255), notnull: true }
              object: { type: string(255), notnull: true }



Re: Drop Down Values from query [message #103423 is a reply to message #103412 ] Mon, 02 August 2010 15:50 Go to previous message
cokker  is currently offline cokker
Messages: 582
Registered: January 2007
Location: Germany
Faithful Member
I don't work with Doctrine but it should look like this:

new sfWidgetFormDoctrineChoice(array('model' => 'FsRole',
 'method' => 'yourStringmethod', 'peer_method'=>  'getRoleList'))


greets
Sven

[Updated on: Mon, 02 August 2010 15:50]

Previous Topic:Dynamically Adding a new Form Element
Next Topic:Custom interactions only on selected rows
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software