I'm trying to work with the form dropdown function for the codeigniter form helper.
echo form_dropdown('userCharacters', $userRoster, '', '', 'id="userCharacter"');
If you notice the $userRoster is the array I pass from the controller to the view.
Here's how it shows up when I do a print_r on the array.
Array
(
[0] => stdClass Object
(
[id] => 1
[rosterName] => Kid Wonder
)
[1] => stdClass Object
(
[id] => 3
[rosterName] => Oriel
)
)
However I am getting these errors and not sure why
A PHP Error was encountered
Severity: 4096
Message: Object of class stdClass could not be converted to string
Filename: helpers/form_helper.php
Line Number: 352
A PHP Error was encountered
Severity: 4096
Message: Object of class stdClass could not be converted to string
Filename: helpers/form_helper.php
Line Number: 352
EDIT :
Array
(
[0] => Array
(
[id] => 1
[rosterName] => Kid Wonder
)
[1] => Array
(
[id] => 3
[rosterName] => Oriel
)
)
EDIT 2 : What's supposed to happen is after the user logs in it has the default character id and the role id of the user that is held in the userData array. It runs the library function getRosterList. Inside that function it checks to see if the user has a role id of 4(admin) or 5(superadmin) and if they are then what I want it to do is get ALL the roster members which would include their default character and have it as the selected option. If they are not one of those two roles then I just want it to get the roster members that they control and have the preselected option as the default character id. And if they only have one character then it displays a h1 tag instead of the dropdown.
Controller:
$this->data['userData'] = $this->users->getUserByUserID($this->session->userdata('userID'));
$this->data['userRoster'] = $this->kowauth->getRosterList($this->data['userData']->usersRolesID);
Library (kowauth)
* Get roster list
*
* @param integer
* @return object/NULL
*/
function getRosterList($usersRolesID)
{
// Check args
if(!is_numeric($usersRolesID)) { throw new Exception('Non-numeric $usersRolesID provided to getRosterList()'); }
if (($usersRolesID == 4) || ($usersRolesID == 5))
{
return $this->ci->users->getAllRoster();
}
else
{
return $this->ci->users->getRosterByUserID($this->ci->session->userdata('userID'));
}
}
Model:
/**
* Get roster list
*
* @return object/NULL
*/
function getAllRoster()
{
$this->db->select('id');
$this->db->select('rosterName');
$this->db->select('rosterStatusID');
$this->db->from('rosterList');
$this->db->order_by('rosterName');
$query = $this->db->get();
if ($query->num_rows() > 0)
{
return $query->result();
}
return null;
}
/**
* Get list of roster by user ID
*
* @return object/NULL
*/
function getRosterByUserID($userID)
{
// Check args
if (!is_numeric($userID)) { throw new Exception('Non-numeric $userID provided to getRosterByUserID()'); }
$this->db->select('id');
$this->db->select('rosterName');
$this->db->from('rosterList');
$this->db->where('userID', $userID);
$this->db->order_by('rosterName');
$query = $this->db->get();
if ($query->num_rows() > 0)
{
return $query->result_array();
}
return null;
}
View:
<?php
echo '<pre>';
print_r($userRoster);
echo '</pre>';
if (count($userRoster) == 1)
{
echo '<h1>'.$userRoster->rosterName.'</h1>';
}
else
{
$options = array (
$userRoster['id'] => $userRoster->rosterName
);
echo form_dropdown('userCharacters', $options, '', 'id="userCharacter"');
}
?>
Anybody have any ideas on this?