Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Getting DB results as read only exception from DB::select
  • I'm running a query using DB::select and getting the results as an object. I can see that the result is an array of stdClass objects which is whitelisted in the general config but I keep getting the error, Fuel\Core\Fuel_Exception [ Error ]: Database results are read-only. I have a method in the model User like this
    function get_photos()
      $result = DB::select("photos.id","photos.caption")
                    ->from('photos')
                    ->where('photos.user_id', $this->user_id)
                    ->as_object()
                    ->execute();
    return $result;
    }
    

    which i'll get in the controller and pass to the view like this
    $data['photos'] = $user->get_photos();
    
    $this->template->content = View::factory('profile', $data);
    

    if I set the autoencode flag to false then the exception is not thrown Maybe I'm not understanding the security auto encoding.
  • A Huzz wrote on Thursday 18th of August 2011:

    Yeah, before I tried adding the method as_assoc() to the query which still gave the warning, however if I do
    function get_photos(){
      $result = DB::select("photos.id","photos.caption")
                    ->from('photos')
                    ->where('photos.user_id', $this->user_id)
                    ->execute();
    return $result->as_array();
    }
    
    
    That will work. This feels like more of a work around, I still don't get why an array of stdClass objects should throw that exception.

Howdy, Stranger!

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

In this Discussion