Trait luya\admin\traits\LazyDataLoadTrait
Trait to enable lazy load for NgRest plugins.
For a example for CheckboxList:
public function ngRestAttributeTypes()
{
return [
'genres' => ['checkboxList', 'data' => function () {
return new Query()->all();
}],
];
}
Protected Methods
Method | Description | Defined By |
---|---|---|
lazyLoadData() | If the given data is a closure it will call it and return the result of the function. | luya\admin\traits\LazyDataLoadTrait |
Method Details
If the given data is a closure it will call it and return the result of the function.
Function will only execute if the data are really need to load.
If the given data is no closure it will return the directly data.
$this->lazyLoadData(function () {
return Query::find()->all();
});
protected mixed|Traversable lazyLoadData ( $data ) | ||
$data | mixed|Closure |
protected function lazyLoadData($data)
{
if (is_callable($data)) {
return call_user_func($data);
}
return $data;
}