Answer the question
In order to leave comments, you need to log in
Yii2 does not cache entire additional requests - what to do?
Enable caching:
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=mysql;dbname=my',
'username' => 'root',
'password' => 'pass',
'charset' => 'utf8',
// включение кэширование схемы БД
'enableSchemaCache' => true,
];
// Так
'schemaCacheDuration' => 0,
'schemaCache' => 'cache',
//и так тоже
'schemaCacheDuration' => 3600,
'cache' => [
'class' => 'yii\caching\FileCache',
],
Answer the question
In order to leave comments, you need to log in
As a result, it turned out that if the owner of the cache folder is not www-data, then requests are not cached
Treatment:
1. Change the owner of the cache folder
chown www-data:www-data cache
2. Delete everything from the cache directory.
rm -rf ./*
I think that to solve your problem, you need to use lazy and eager loading .
There are two tables "customer" and "orders" which are related
class Customer extends ActiveRecord
{
public function getOrders()
{
return $this->hasMany(Order::className(), ['customer_id' => 'id']);
}
}
class Order extends ActiveRecord
{
public function getCustomer()
{
return $this->hasOne(Customer::className(), ['id' => 'customer_id']);
}
}
$customers = Customer::find()
->with('orders')
->all();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question