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 » General discussion » [resolved] Gender dropdown with admingenerator
[resolved] Gender dropdown with admingenerator [message #5175] Wed, 19 April 2006 15:32 Go to next message
fransica  is currently offline fransica
Messages: 16
Registered: April 2006
Location: Netherlands
Junior Member
Hello.

I want a dropdownmenu for my genderselection in the useradministration app. Gender is stored in an varchar(1). In the generated CRUD the gender input is a textfield. For easy usage this schould be a dropdown menu with the values M(ale) F(emale) and U(nkown).

Who can help me?

[Updated on: Thu, 20 April 2006 13:50] by Moderator

Re: Gender dropdown with admingenerator [message #5192 is a reply to message #5175 ] Wed, 19 April 2006 17:38 Go to previous messageGo to next message
francois  is currently offline francois
Messages: 1636
Registered: October 2005
Faithful Member
Replace the 'gender' in 'display:' by '_gender' to use a partial field.

Then in the templates dir, create a '_gender.php' file with:
<select name="gender" id="gender">
  <option value="M">Male</option>
  <option value="F">Female</option>
  <option value="U" selected="selected">Unknown</option>
</select>


And that's it.

One thing to remember with the admin generator: it doesn't limit you. It there is something that it doesn't do, just use a partial field and do it yourself.
Re: Gender dropdown with admingenerator [message #5232 is a reply to message #5175 ] Thu, 20 April 2006 11:49 Go to previous messageGo to next message
fransica  is currently offline fransica
Messages: 16
Registered: April 2006
Location: Netherlands
Junior Member
Nice!
Next thing. How can I set the selected for a excisting user?
My app is called 'backend' and my 'module' is called users. My model is generated by propel. I used $users->getGender() to access the gender of a object from Tblusers.php but this doesn't work. The error i get is
Notice: Undefined variable: users 
Fatal error: Call to a member function getGender() on a non-object

What is the correct way then?
Re: Gender dropdown with admingenerator [message #5234 is a reply to message #5232 ] Thu, 20 April 2006 12:18 Go to previous messageGo to next message
francois  is currently offline francois
Messages: 1636
Registered: October 2005
Faithful Member
did you try $tblusers->getGender() ?

Buy the way, it is recommended to name your tables with singular names when you use symfony.
Re: Gender dropdown with admingenerator [message #5235 is a reply to message #5175 ] Thu, 20 April 2006 12:36 Go to previous messageGo to next message
fransica  is currently offline fransica
Messages: 16
Registered: April 2006
Location: Netherlands
Junior Member
I tried that. It doesn't work Sad
How do i get singular from my build-model? All my tables in the database are named like tblUsers, tblUserRoles, etc. Then when i use symfony propel-build-schema and after that symfony propel-build-model al the generated names in the model are called like Tblusers and Tbluserroles. Can this be the cause for my problem?
Re: Gender dropdown with admingenerator [message #5236 is a reply to message #5235 ] Thu, 20 April 2006 12:54 Go to previous messageGo to next message
francois  is currently offline francois
Messages: 1636
Registered: October 2005
Faithful Member
I don't think that it's the cause of your problem. And note that the actual table names (in your database) and the Propel name for the corresponding object can be completely distinct, that's what the phpName attribute is made for.

For your variable problem, normally $users should work, so I advise you to look at the generated code in the cache/ folder to see hpw the current object is named.
Re: Gender dropdown with admingenerator [message #5237 is a reply to message #5175 ] Thu, 20 April 2006 13:22 Go to previous messageGo to next message
fransica  is currently offline fransica
Messages: 16
Registered: April 2006
Location: Netherlands
Junior Member
It works! Thanks for the support!
My _gender_dropdown.php
<?php 
echo select_tag('gender', options_for_select(Array('U' => 'Unknown', 'M' => 'Male', 'F' => 'Female'), $tblusers->getGender()))
?>

And the generator.yml
generator:
  class:              sfPropelAdminGenerator
  param:
    model_class:      Tblusers
    theme:            default
    
    fields:
      gender_dropdown:  { name: Gender }

    edit:
      display:
        "General information":  [surname, firstname, _gender_dropdown]

And I will regenerate my model using phpName.

[Updated on: Thu, 20 April 2006 13:22]

Re: [resolved] Gender dropdown with admingenerator [message #5504 is a reply to message #5175 ] Wed, 26 April 2006 17:23 Go to previous messageGo to next message
Seboss  is currently offline Seboss
Messages: 20
Registered: April 2006
Junior Member
My question is slightly off-topic but I think it fits in this thread.

I want to create product categories with different cultures. I store supported cultures in a culture table.
The create category form has a culture dropdown list populated from the culture table thanks to a _culture partial but it feels a bit clumsy.

Is there an easy way to generate a dropdown list with data from the culture table with generator.yml ?

[Updated on: Wed, 26 April 2006 17:23]

Re: [resolved] Gender dropdown with admingenerator [message #65692 is a reply to message #5504 ] Fri, 21 November 2008 10:07 Go to previous message
shamsh  is currently offline shamsh
Messages: 2
Registered: November 2008
Location: Dhaka
Junior Member
may be this can help you.

http://snipplr.com/view/4057/populate-objectselecttag-with-y our-own-objects-in-symfony/
Previous Topic:Date validation on raw dates.
Next Topic:[FIXED in 1.1.5] symfony outputs garbage characters before and after html code
Goto Forum:
  

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