arrays - yii activerecord return object -


i using using yii2 in basic template mysql database
why code returns object instead of array of selected records database when use var_damp($rooms) output seems object , not array of selected record in array format; body can help

 public function actionindexfiltered()     {         $query = room::find();          $searchfilter = [             'floor' => ['operator' => '', 'value' => ''],              'room_number' => ['operator' => '', 'value' => ''],              'price_per_day' => ['operator' => '', 'value' => ''],          ];          if(isset($_post['searchfilter']))         {             $fieldslist = ['floor', 'room_number', 'price_per_day'];              foreach($fieldslist $field)             {                 $fieldoperator = $_post['searchfilter'][$field]['operator'];                 $fieldvalue = $_post['searchfilter'][$field]['value'];                  $searchfilter[$field] = ['operator' => $fieldoperator, 'value' => $fieldvalue];                  if( $fieldvalue != '' )                 {                     $temp1=$query->andwhere([$fieldoperator, $field, $fieldvalue]);                 }             }         }         $room1=$temp1->all();         $rooms = $query;          return $this->render('indexfiltered', [ 'rooms' => $rooms, 'searchfilter' => $searchfilter,'room1'=>$room1 ]);        } 

output , shows code return query object , not array of query execution on database , checked code using var_dump function results is returning object not array

 object(yii\db\activequery)[70]       public 'sql' => null       public 'on' => null       public 'joinwith' => null       public 'select' => null       public 'selectoption' => null       public 'distinct' => null       public 'from' =>          array (size=1)           0 => string 'room' (length=4)       public 'groupby' => null       public 'join' => null       public 'having' => null       public 'union' => null       public 'params' =>          array (size=0)           empty       private '_events' (yii\base\component) =>          array (size=0)           empty       private '_behaviors' (yii\base\component) =>          array (size=0)           empty       public 'where' =>          array (size=3)           0 => string '=' (length=1)           1 => string 'room_number' (length=11)           2 => string '3' (length=1)       public 'limit' => null       public 'offset' => null       public 'orderby' => null       public 'indexby' => null       public 'emulateexecution' => boolean false       public 'modelclass' => string 'app\models\room' (length=15)       public 'with' => null       public 'asarray' => null       public 'multiple' => null       public 'primarymodel' => null       public 'link' => null       public 'via' => null       public 'inverseof' => null 

this code return dataprovider .. alias code models /active record

$query = room::find(); 

for obtain models can use

$roommodels= room::find()->all();  

in result collection of obejct (models) of class room

if need array can use

$roomarray = room::find()->asarray()->all();  

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -