Quote:I agree with tolyx, I would love to be able to use form_dropdown with datamapper… something like
Don't know whether this is the kind of thing. I created a library for a selectbox class. You basically point it at a model and it bases the drop down menu on the model.
So you'd write:
Code:
$select = new Selectbox('Section'); // This creates the instance of the selectbox based on the section model from my application
$select->draw(); // This echos the HTML to the page
This is the quickest way to do it, and relies on the class defaults which are 'id' for the value and 'label' for the label. I find a lot of my tables have a label column. You might want to change the class default for that if your tables tend to have another common field. Or just say:
Code:
$select = new Selectbox();
$select->model('User'); // Make a drop down menu of the User model
$select->label('username'); // Column to use as the display text for the options. Defaults to 'label' column
$select->value('user_id'); // Defaults to id
$select->condition('activated','1');// Make a drop down of only active users
$select->draw(); // Echo the HTML
also supports method chaining:
Code:
$select = new Selectbox('User');
$select->label('username')->condition('activated','1')->draw();
Other options are styles: array of CSS styles to add to the field, classname: CSS class name, disabled, multiple, size.
Don't know if it will help, but thought I'd post it up here because it seemed relevant!
Class is attached if anyone's interested. I keep it in my application/libraries folder.
Cheers,
Matt