Want to get maximal value, but query doesn't work

I try to program a query in Yii2, which shows me the highest value of the database. Unfortunately, I get error message: "Call to a member function all() on string" How to patch this problem?


namespace app\controllers;

use yii\web\Controller;

use yii\data\Pagination;

use app\models\Country;

class CountryController extends Controller


    public function actionIndex()


 $query = Country::find();        

 $countries = $query->select('population')->max('population')



        return $this->render('index', [

            'countries' => $countries,





You have to decide what you want.

"all" gives you all records that match the query, i.e. an array of ActiveRecords.

"max" gives you the maximum value of one column, just one scalar value.