Answer the question
In order to leave comments, you need to log in
Lazy loading data from database?
I'm trying to do the so-called "lazy" loading of data to reduce the number of requests to one.
protected $_allTimes;
/**
* Получить все временные отрезки
* @return Time[]
* @throws NotFoundHttpException
*/
public function getAllTimes() {
if(!isset($this->_allTimes)){
echo " я запрос time выполняюсь 1 раз! ";
$this->_allTimes = Time::find()
->where($this->enabledScope)
->orderBy('from')
->all();
if($this->_allTimes===null){
throw new NotFoundHttpException('Ошибка. Не задан ни один временной промежуток!');
}
}
return $this->_allTimes;
}
public function getEnabledScope(){
return ['removed'=>0, 'enabled'=>1]
}
Answer the question
In order to leave comments, you need to log in
How is the getAllTimes method called? IMHO there are problems with the call context. In theory, it should be a singleton. Do you happen to create a new object each time?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question