Hey there!
I have two controllers/models in my plugin - Cars and Items. Car hasMany items. Item belongTo Car. In my Cars backend list I've added column with 'Info' button to show detailed information of a Car in popup, calling action onShowInfo() of Cars controller.
Info button's partial:
<a
target="_blank"
class="btn btn-default btn-sm btn-info oc-icon-info"
data-control="popup"
data-handler="onShowInfo"
data-request-data="car_id: <?= $record['id'] ?>">
Info
</a>
onShowInfo action in Cars controller:
public function onShowInfo() {
if (post('car_id')) {
$car = CarModel::with('manufacturer', 'auto', 'transmission_type', 'carcase', 'engine_type', 'engine_features', 'color')->find(post('car_id'));
}
return [
'result' => $this->makePartial('car_info', ['var' => $car])
];
}
It works nice. But let's say I have to call this action from my Items list or any other place? How can I achieve this without adding exactly the same action to another controllers? I have tried passing target controllers name to 'data-handler' attribute like this:
data-handler="Cars::onShowInfo"
but unfortunately it throws exception: "A widget with class name 'Cars' has not been bound to the controller" on line 512 of /modules/backend/classes/Controller.php"
I'm sorry for a noob question. Thanks in advance.
Last updated