Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
why this error simple orm model_user::find()
  • RuntimeException [ Error ]: Object class "Orm\Query" could not be converted to string or sanitized as ArrayAcces. Whitelist it in security.whitelisted_classes in app/config/config.php to allow it to be passed unchecked. What does this mean ? my user model and controller works fine auth works fine .
     public function action_index()
     {
      $this->template->title   = "simple text title " ; // works fine 
      $this->template->logged_in  =  true ;   // works fine 
      
      $data['username']  = \Session::get('username') ; // works fine  can see it in view 
    
      $data['users']  = Model_User::find('all') ;  // works fine can list them in view with foreach(users as user)
    
    
                    $suser = \Session::get('username')  ;
      
                    // this does not seem to work ..   gives me this error .. however  find all works perfect 
      $data['singleuser'] = Model_User::find()->where('username', $suser ); 
       
      $view =  View::factory('record/index', $data) ;
    
      $this->template->content = $view ; 
     }
    
    

    I don't get it .. what do i do
    thanks !! a lot !! gr.
  • You're not doing a get(), so it will return a query object, which when assigned to the view, can't be converted to string. See http://fuelphp.com/docs/packages/orm/relations/intro.html#usage
  • Harro Verton wrote on Tuesday 28th of June 2011:
    You're not doing a get(), so it will return a query object, which when assigned to the view, can't be converted to string. See http://fuelphp.com/docs/packages/orm/relations/intro.html#usage

    Woauw ... :-) I still don't really get it but is ok .. works fine like you suggested thanks!!
    // this works fine now ..  
    $data['suser'] = Model_User::find()->where('username', \Session::get('username') )->get_one(); 
    
    // but this one works fine as well  but don't see the difference with my first one 
    // $data['suser'] = Model_User::find()->where('username', \Session::get('username') ) ;
    
    $data['suser'] = Model_User::find('', array('where' => array('username' => \Session::get('username'))));
    

    but this has more to do with me being new to everything .. haha Thank you !!
  • Model::find() returns a query builder object, where you can use QB methods like where(), limit(), order_by() to filter the results of the query. Each method returns the object itself, so you can chain methods. Which means you need to finish your chain with get(), to indicate you want to execute the query you've been building. Model:find('all') does exactly that, it runs the query and returns all results. You can view it as an alias of Model::find()->get();

Howdy, Stranger!

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

In this Discussion