P
P
Padre2018-02-04 12:03:06
Yii
Padre, 2018-02-04 12:03:06

How to select data from Yii2 DB?

The address:

'rules' => [
                'jobdb' => 'job/jobdb',
            ],

Method in controller:
public function actionJobdb()
    {
        $array = JobList::getAll();
        return $this->render('joblist',['varInView' => $array]);
    }

Then, according to the manual, I created the JobList.php model in models, etc., but the error:
Class 'frontend\controllers\JobList' not found

And it shows a line with an error:
$array = JobList::getAll();
So why is it looking for the JobList class in the controller and not in the model? Should it be placed in the controller? What to write there and what then to leave in the model?
PS Now in the model like this:
class JobList extends Model
{
    public static function tableName(){
        return 'tags'; // Имя таблицы в БД
    }

    public static function getAll(){
        $data = self::find()->all();
        return $data;
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2018-02-04
@yii16

The problem is that the model is in its own space, the controller is in its own. Understand how namespaces work and there will be no similar problems and questions about them in the future

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question