Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Display db rows in Input::select() with ORM
  • I have a model for categories on my site, and I want to display all of the categories in a select drop down. Unfortunately, Input::select() only accepts arrays, not objects, so I need to convert it to a multi-dimensional array. There doesn't seem to be a way to do this that's built-in, so I'm guessing I'll have to write this myself, right?
  • get_object_vars( object $object ). Random idea: You can try type-cast object to array. Ha, ha!
  • A couple of points:
    1. There is no Input::select() method, you probably mean Form::select()?
    2. Does this really belong here in the Orm forum? (it doesn't seem to, this seems to be about input for the Form class)
    3. There's a method to_array() which you can call on each Orm\Model instance to get the associative array representation of that model.
    Raitis Stengrevics wrote on Wednesday 1st of June 2011:
    get_object_vars( object $object ). Random idea: You can try type-cast object to array. Ha, ha!
    No you can't, neither get_object_vars() nor casting to an array will work with Orm\Model instances.
  • Jelmer Schreuder wrote on Thursday 2nd of June 2011:
    A couple of points:
    1. There is no Input::select() method, you probably mean Form::select()?
    2. Does this really belong here in the Orm forum? (it doesn't seem to, this seems to be about input for the Form class)
    3. There's a method to_array() which you can call on each Orm\Model instance to get the associative array representation of that model.
    Raitis Stengrevics wrote on Wednesday 1st of June 2011:
    get_object_vars( object $object ). Random idea: You can try type-cast object to array. Ha, ha!
    No you can't, neither get_object_vars() nor casting to an array will work with Orm\Model instances.

    Sorry, I of course meant Form::select(). Anyways I felt it belonged under ORM, because I was specifically looking for a way to convert the ORM object to an array. And Jelmer is right, you can't cast to an array or use get_object_vars because the properties (as in, the data from the db) on Orm\Model instances are access with magic methods (eg __get() and __set()) they aren't actually properties at all, so they don't end up in the resulting array.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion