Add index_onDelete method to ListController behavior.
This commit is contained in:
parent
9dc1b4d836
commit
c17e9b0e33
|
|
@ -3,10 +3,9 @@
|
|||
use Str;
|
||||
use Lang;
|
||||
use Event;
|
||||
use Flash;
|
||||
use ApplicationException;
|
||||
use Backend\Classes\ControllerBehavior;
|
||||
use League\Csv\Writer;
|
||||
use SplTempFileObject;
|
||||
|
||||
/**
|
||||
* List Controller Behavior
|
||||
|
|
@ -246,6 +245,29 @@ class ListController extends ControllerBehavior
|
|||
$this->makeLists();
|
||||
}
|
||||
|
||||
public function index_onDelete()
|
||||
{
|
||||
if (method_exists($this->controller, 'onDelete')) {
|
||||
return $this->controller->onDelete();
|
||||
}
|
||||
|
||||
$model = $this->config->modelClass;
|
||||
|
||||
if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {
|
||||
foreach ($checkedIds as $id) {
|
||||
if (!$record = $model::find($id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$record->delete();
|
||||
}
|
||||
|
||||
Flash::success(Lang::get('backend::lang.list.delete_selected_success'));
|
||||
}
|
||||
|
||||
$this->controller->listRefresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the widget collection.
|
||||
* @param string $definition Optional list definition.
|
||||
|
|
|
|||
Loading…
Reference in New Issue