yii2tech/filedb

Error using yii2tech\filedb\Query;

gitrequests opened this issue · 3 comments

If i use \yii2tech\filedb\ActiveRecord it is work fine.

But yii2tech\filedb\Query exit with error:
Call to a member function getQueryProcessor() on null
in D:\Data\OpenServer\5.2.4\domains\site.my\vendor\yii2tech\filedb\Query.php at line 110

Controller:

<?php

namespace app\controllers;

use Yii;
use yii\web\Controller;
use yii\filters\VerbFilter;

use yii2tech\filedb\Query;

class SiteController extends Controller
{

    public $layout = 'web';

    public function actionIndex()
    {
        //$items = Items::find()->all(); // <-- It is work fine!
        $query = new Query();
        $query->from('Items');
        $rows = $query->all(); // <-- Error!

        return $this->render('index', ['items' => $items]);
    }

    public function actionAbout()
    {
        return $this->render('about');
    }

}

filedb file (@app/data/Items.php):

<?php

return [
    1 => [
        'name' => 'admin',
        'description' => 'Site administrator',
    ],
    2 => [
        'name' => 'member',
        'description' => 'Registered front-end user',
    ],
];

Yii2 config:

//...
 'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'db' => require(__DIR__ . '/db.php'),
        'filedb' => [
            'class' => 'yii2tech\filedb\Connection',
            'path' => '@app/data',
        ],
    ],
    'params' => $params,
//...

Did everything according to Your documentation.

This happens because there is no default connection fetching inside the Query.
At the present state, you can bypass the issue passing yii2tech\filedb\Connection instance to the Query::all() method:

$query = new Query();
$query->from('Items');
$rows = $query->all(Yii::$app->filedb);

Resolved by commit a183ab7

It work! Thx!