Answer the question
In order to leave comments, you need to log in
How to solve "Class ... not found" error in Yii2?
Hello. I have the following problem.
When accessing the controller action, the error "Class 'app\models\customer\CustomerRecord' not found" is thrown.
The contents of the index.php file
<?php
ini_set('display_errors', true);
define('YII_DEBUG', true);
require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
$config = require(__DIR__ . '/../config/web.php');
(new yii\web\Application($config))->run();
<?php
namespace app\models\customer;
use yii\db\ActiveRecord;
class CustomerRecord extends ActiveRecord
{
public static function tableName()
{
return 'customer';
}
public function rules()
{
return [
['id', 'number'],
['name', 'string', 'max' => '256'],
['birth_date', 'date', 'format' => 'Y-m-d'],
['notes', 'safe']
];
}
}
<?php
namespace app\controllers;
use app\models\customer\Customer;
use app\models\customer\CustomerRecord;
use app\models\customer\Phone;
use app\models\customer\PhoneRecord;
use yii\web\Controller;
class CustomerController extends Controller
{
public function actionIndex()
{
$record = $this->findRecordsByQuery();
return $this->render('index', compact('record'));
}
public function actionAdd()
{
$customer = new CustomerRecord;
$phone = new PhoneRecord;
return $this->render('add', compact('customer', 'phone'));
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question