yii2yii-extensions

Error Calling unknown method: omgdef\multilingual\MultilingualQuery::sort()?


Good afternoon, help me figure it out, using the OmgDef/yii2-multilingual-behavior extension, swears at this line:

    public function actionIndex()
    {
        $data = new ActiveDataProvider([
            'query' => FaqLang::find()->multilingual()->sort(), //error here
        ]);
        return $this->render('index', [
            'data' => $data
        ]);
    }

My overridden model that stores the sort() method

<?
namespace admin\base;

/**
 * Base active query class for models
 * @package admin\base
 */
class ActiveQuery extends \yii\db\ActiveQuery
{
    /**
     * Order by order_num
     * @return $this
     */
    public function sort()
    {
        $this->orderBy(['order_num' => SORT_ASC]);
        return $this;
    }
}

Solution

  • You could try using the sort property of the ActiveDataProvider.

    $data = new ActiveDataProvider([
        'query' => FaqLang::find()
            ->multilingual()
            ->select(['id','question','answer']),
        'sort' => [
            'defaultOrder' => ['order_num' => SORT_ASC],
        ],
    ]);
    

    To select columns use the select() method of the ActiveQuery object.

    If you are using GridView to display results, you can also use it's columns property.