Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Model_Crud::to_array($custom)
  • In the docs it says that Model_Crud::to_array() does not take any parameters.

    But looking at the method, it seems that it does.

    It looks like you can set custom data to your model that gets added to the resulting array.

    Where would one set that custom data.

    Is this for some specific internal function?  

    Is there a reason the parameters are not documented?


    Just curious....  :)


  • philipptempelphilipptempel
    Accepted Answer
    It does not add custom data to the returned array but will return also the given custom data. Every model can have data from the fields in the table and also custom data that you assign similarly to assigning a property to a object of type stdClass. These values can then be returned as well given the keys in the $custom array.
  • HarroHarro
    Accepted Answer
    We're talking about Model_Crud, right?

    In that case to_array() doesn't have any parameters, see https://github.com/fuel/core/blob/1.8/develop/classes/model/crud.php#L712
  • Sorry, my mistake:  Orm\Model  not Model_Crud.
  • HarroHarro
    Accepted Answer
    Ah, ok.

    The ORM model uses the from_array() method. It optionally takes three boolean's as arguments, whether or not to include custom model properties, whether or not to recurse, and whether or not to include EAV values.

    If you enable recursion you might get into an endless loop if children relate back to parents, so use that with care.

    You can filter results using the $_to_array_exclude array. It doesn't have a setter, it was designed to define a static list in the model itself, so if you need more dynamic filtering, you need a setter method, either in the model, in a base model, or using a trait.
  • I haven't use traits yet in PHP.  Thanks for the idea.  :)

Howdy, Stranger!

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

In this Discussion