Noob on dropdown list

I apologize for not having enought time to research on this, I’m in a hurry but I need to travel back home now. I am hoping that someone will enlighten me while I’m on my way home.

I created a this public function:


public function getYesOrNo() {

		$list[0] = 'No';

		$list[1] = 'Yes';


		return $list;

	}

and I want to add "Select" so in my _form, i put


<?php echo $form->dropDownList($model,'IsEmployee',Users::getYesOrNo(),array('prompt'=>'Select') ); ?>

I want "Select" to be the default value for this, not "Yes".

Yeah I know this is so simple, sorry for being a beginner and thanks for your answer.

Looks right to me.;)

could be that $model->IsEmployee has already a value… and that’s why “Yes” is selected…

well, ‘IsEmployee’ is a field of Users table, which doesn’t have any value yet.

If my approach is incorrect, please correct me. What is the best approach so that I can have a dropdown list that has "Select","Yes",and "No" options.

As jacmoe wrote, all seems fine… "select" should be the first value not "yes"

That’s what I though also, thus I wrote the code. And it’s not working like what we think it should do.

How do I make a dropdown list with options hard coded btw?


<?php echo $form->dropDownList($model,

'IsEmployee',

array(0 => 'No', 1 => 'Yes'),

array('prompt'=>'Select') ); ?>

Your first approach is actually correct, as well as jacmoe’s. Maybe it has something to do with your database structure. Take a look at your Users table and see if it is set to a default value (I’m thinking it might be set to default ‘1’, thus making your dropdown to default ‘Yes’). If you want it to default to ‘Select’, it should be set to ‘default NULL’ or no default value at all.

Yeah, you’re actually correct. IsEmployee field is set to default to ‘1’, and after changing it to default ‘0’, dropdown defaults to ‘No’. I changed it to default NULL, and yes! Neither ‘Yes’ or ‘No’ was selected by default, but the ‘Select’.

Thanks!

Where is it documented?

Thanks