Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7762335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:22:28+00:00 2026-06-01T14:22:28+00:00

I’m trying to work with the form dropdown function for the codeigniter form helper.

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:22:30+00:00Added an answer on June 1, 2026 at 2:22 pm

    You’re currently passing an array of objects. I believe that your $userRoster array should be formatted like this:

    Array
    (
         1 => 'Kid Wonder'
         3 => 'Oriel'
    )
    

    Also, I believe that form_dropdown only takes four parameters and you’re trying to pass it five. You might want to move that last argument into the fourth spot:

    echo form_dropdown('userCharacters', $userRoster, '', 'id="userCharacter"');
    

    Should produce:

    <select name="userCharacters" id="userCharacter">
    <option value="1">Kid Wonder</option>
    <option value="3">Oriel</option>
    </select>
    

    Which I think is what you’re going for!

    http://codeigniter.com/user_guide/helpers/form_helper.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.