Yii Framework Forum: Display Two Columns In A Listbox - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Display Two Columns In A Listbox how to display two columns in a listbox Rate Topic: -----

#1 User is offline   kaif 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 04-January 13
  • Location:India

Posted 19 March 2013 - 12:49 AM

I have a dropdown list in my view, it is populating from driver_master table, driver_master table contains first_name, last_name,driver_id etc., I want to show the first_name and last_name as display text and driver_id as value in list, I want to display driver_id as value and first_name,last_name as display text.I done the following method but still i did not get the result.

In Model:

function getFullName()
{
return $this->first_name.' '.$this->last_name;
}

function getDrivers()
{
$drivers = driverMaster::model()->findAll();
$list = CHtml::listData($drivers, 'driver_id', 'fullName');
return $list;
}

In View:

echo $form->dropDownList($model,'driver_id',$model->getDrivers());


i am getting the driver_id but i could not get first_name & last_name
0

#2 User is offline   mbala 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 131
  • Joined: 21-July 12
  • Location:Chennai, Tamilnadu, India

Posted 19 March 2013 - 01:54 AM

it is working fine for me
0

#3 User is offline   Lal Zada 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 125
  • Joined: 06-November 12
  • Location:Lahore, Pakistan

Posted 19 March 2013 - 02:37 AM

View Postkaif, on 19 March 2013 - 12:49 AM, said:

I have a dropdown list in my view, it is populating from driver_master table, driver_master table contains first_name, last_name,driver_id etc., I want to show the first_name and last_name as display text and driver_id as value in list, I want to display driver_id as value and first_name,last_name as display text.I done the following method but still i did not get the result.

In Model:

function getFullName()
{
return $this->first_name.' '.$this->last_name;
}

function getDrivers()
{
$drivers = driverMaster::model()->findAll();
$list = CHtml::listData($drivers, 'driver_id', 'fullName');
return $list;
}

In View:

echo $form->dropDownList($model,'driver_id',$model->getDrivers());


i am getting the driver_id but i could not get first_name & last_name




its fine with me.....check ur first_name & last_name
Is it fast? Is it secure? Is it professional? Is it right for my next project? Yes, it is

Linkedin Facebook Twitter Google+
0

#4 User is offline   kaif 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 04-January 13
  • Location:India

Posted 19 March 2013 - 05:24 AM

View PostLal Zada, on 19 March 2013 - 02:37 AM, said:

its fine with me.....check ur first_name & last_name



Thanks for your response, I solved the problem by doing the following method

$models = DriverMasterModel::model()->findAll();
$data = array();

foreach ($models as $rows)
$data[$rows->driver_id] = $rows->first_name.' '.$rows->last_name;

echo $form->dropDownList($model, 'driver_id', $data ,array('prompt' => 'Select'));
0

#5 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 19 March 2013 - 01:54 PM

/* moved from Bug Discussions */
"Less noise - more signal"
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users