public function edit($id) { if ($this->shouldLockIfNoPermission('data.edit')) { return; } $modelDevice = new Device($this->db); if ($this->request->is('post')) { if ($modelDevice->updateDeviceById($id, $_POST)) { $this->flash->success('Updated device successfully!'); } else { $this->flash->addMany($modelDevice->getAllMessages(), 'warning'); } return $this->redirect('/devices/view/' . $id); } $item = $modelDevice->findById($id); if ($item === null) { $this->flash->error('Unable to find device!'); return $this->redirect('/customers'); } $item['date_completed'] = $this->formatNullableDate($item['date_completed']); $this->set('item', $item); $modelCustomer = new Customer($this->db); $customer = $modelCustomer->findById($item['customer_id']); if ($customer === null) { $this->flash->error('Unable to get customer information!'); return $this->redirect('/customers'); } $this->set('customer', $customer); }