. * */ namespace Vvveb\Controller; use function Vvveb\model; use Vvveb\System\Traits\Crud as CrudTrait; use Vvveb\System\Traits\Listing as ListingTrait; class Listing extends Base { use ListingTrait, CrudTrait { ListingTrait::index as get; CrudTrait::delete insteadof ListingTrait; } function __construct() { $this->redirect = false; $this->fullPost = true; } function post() { $model = model($this->type); $data = $this->request->post ?? []; if ($model) { $errors = $model->validate($data, 'add', $this->type); if ($errors) { $this->notFound(['errors' => $errors], 500); } } $this->redirect = false; $this->fullPost = true; return $this->save(); } function index() { $results = $this->get(); $this->view->success[] = '%s(s) deleted!'; if (isset($results['count'])) { $count = $results['count'] ?: 0; $limit = $results['limit'] ?: 0; $page = $results['page'] ?: 1; //$pages = ($count && $limit) ? ceil($count / $limit) : 0; $this->response->addHeader('X-V-count', $count); $this->response->addHeader('X-V-limit', $limit); //$this->response->addHeader('X-V-page', $page); //$this->response->addHeader('X-V-pages', $pages); } return $results[$this->type] ?? []; } }