W
W
WildJust2016-12-11 20:29:15
Yii
WildJust, 2016-12-11 20:29:15

How to work with aliases in Yii2?

There is a sample

$stats = Viewstat::find()
            ->select([
                'count(prod_id) AS prodCount',
                'daystat'
            ])
            ->where(['prod_id' => $id])
            ->groupBy('daystat')
            ->one();

When trying to access the view, it says Getting unknown property: frontend\models\Viewstat::prodCount
print_r($stats['prodCount']);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2016-12-12
@WildJust

$stats = Viewstat::find()
    ->select([
        'prodCount'=>'count(prod_id)',
        'daystat'
    ])
    ->where(['prod_id' => $id])
    ->groupBy('daystat')
    ->one();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question