M
M
Maxim2016-04-14 16:14:48
Yii
Maxim, 2016-04-14 16:14:48

What does yii2 output?

There is a database named u13461 (it has a result table and 3 fields id, date, result)
I create a model file results.php (In the models folder)
I write here

namespace app\models;

use yii\db\ActiveRecord;

class results extends ActiveRecord
{
    const STATUS_INACTIVE = 0;
    const STATUS_ACTIVE = 1;

    /**
     * @return string название таблицы, сопоставленной с этим ActiveRecord-классом.
     */
    public static function tableName()
    {
        return 'result';

    }
}

Further in the controller SiteController I write
use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\filters\VerbFilter;
use app\models\EntryForm;
use app\models\results;

class SiteController extends Controller
{
    public function actionIndex()
    {
         $query = results::find()->all();
            return $this->render('index', [
                'query' => $query
            ]);
        }
}

In the views file index.php I write:
echo "<pre>";
    print_r($query);
    echo "</pre>";

As a result, in addition to the data from the database, I also get a bunch of data in an incomprehensible structure and the data from the database is duplicated.
Why?
Here's what it shows:
Array
(
    [0] => app\models\results Object
        (
            [_attributes:yii\db\BaseActiveRecord:private] => Array
                (
                    [id] => 6
                    [date] => 
                    [result] => 0
                )

            [_oldAttributes:yii\db\BaseActiveRecord:private] => Array
                (
                    [id] => 6
                    [date] => 
                    [result] => 0
                )

            [_related:yii\db\BaseActiveRecord:private] => Array
                (
                )

            [_errors:yii\base\Model:private] => 
            [_validators:yii\base\Model:private] => 
            [_scenario:yii\base\Model:private] => default
            [_events:yii\base\Component:private] => Array
                (
                )

            [_behaviors:yii\base\Component:private] => Array
                (
                )

        )

    [1] => app\models\results Object
        (
            [_attributes:yii\db\BaseActiveRecord:private] => Array
                (
                    [id] => 6
                    [date] => 
                    [result] => 0
                )

            [_oldAttributes:yii\db\BaseActiveRecord:private] => Array
                (
                    [id] => 6
                    [date] => 
                    [result] => 0
                )

            [_related:yii\db\BaseActiveRecord:private] => Array
                (
                )

            [_errors:yii\base\Model:private] => 
            [_validators:yii\base\Model:private] => 
            [_scenario:yii\base\Model:private] => default
            [_events:yii\base\Component:private] => Array
                (
                )

            [_behaviors:yii\base\Component:private] => Array
                (
                )

        )

    [2] => app\models\results Object
        (
            [_attributes:yii\db\BaseActiveRecord:private] => Array
                (
                    [id] => 6
                    [date] => 
                    [result] => 0
                )

            [_oldAttributes:yii\db\BaseActiveRecord:private] => Array
                (
                    [id] => 6
                    [date] => 
                    [result] => 0
                )

            [_related:yii\db\BaseActiveRecord:private] => Array
                (
                )

            [_errors:yii\base\Model:private] => 
            [_validators:yii\base\Model:private] => 
            [_scenario:yii\base\Model:private] => default
            [_events:yii\base\Component:private] => Array
                (
                )

            [_behaviors:yii\base\Component:private] => Array
                (
                )

        )

    [3] => app\models\results Object
        (
            [_attributes:yii\db\BaseActiveRecord:private] => Array
                (
                    [id] => 6
                    [date] => 
                    [result] => 0
                )

            [_oldAttributes:yii\db\BaseActiveRecord:private] => Array
                (
                    [id] => 6
                    [date] => 
                    [result] => 0
                )

            [_related:yii\db\BaseActiveRecord:private] => Array
                (
                )

            [_errors:yii\base\Model:private] => 
            [_validators:yii\base\Model:private] => 
            [_scenario:yii\base\Model:private] => default
            [_events:yii\base\Component:private] => Array
                (
                )

            [_behaviors:yii\base\Component:private] => Array
                (
                )

        )

)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2016-04-14
@KidsBout

Decided to add asArray()->all();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question