/** * Execute the controller. * * @throws \Exception * @return mixed Return executed result. */ public function execute() { $session = Ioc::getSession(); $user = $this->input->getVar('user', array()); $user = new Data($user); $user->id = User::get()->id; $user->username = User::get()->username; // Store Session $temp = clone $user; unset($temp->password); unset($temp->password2); $session->set('profile.edit.data', $temp); try { if (!$this->validate($user)) { return false; } $record = new Record('users'); $record->load($user->id); $record->bind($user); $record->check()->store(true); } catch (ValidFailException $e) { $this->setRedirect(Router::buildHttp('admin:profile', ['id' => $user->id ?: '']), $e->getMessage(), 'danger'); return true; } catch (\Exception $e) { if (WINDWALKER_DEBUG) { throw $e; } $this->setRedirect(Router::buildHttp('admin:profile', ['id' => $user->id ?: '']), 'Save fail', 'danger'); return true; } // Save success, reset user session unset($user->password); unset($user->password2); $session->set('user', $user); $session->remove('profile.edit.data'); $this->setRedirect(Router::buildHttp('admin:profile'), 'Save Success', 'success'); return true; }
protected function doExecute() { $data = $this->input->getVar('category'); $data = new Data($data); $data['title'] = trim($data['title']); if (!$data['title']) { $this->setRedirect(Router::build('admin:categories'), 'Title should not be empty', 'danger'); return false; } if (!$data['blog']) { $data['blog'] = Blog::get()->id; } $data['alias'] = OutputFilter::stringURLSafe(trim($data['title'])); $data['alias'] = $data['alias'] ?: OutputFilter::stringURLSafe((string) new Date()); $data['state'] = 1; if (!$data['ordering']) { $max = $this->getMaxOrder($data['blog']); $data['ordering'] = $max + 1; } try { $category = new Record('categories'); if ($data['id']) { $category->load($data['id']); } $category->bind($data); $category->check(); $category->store(true); } catch (\Exception $e) { if (WINDWALKER_DEBUG) { throw $e; } $this->setRedirect(Router::build('admin:categories'), 'Save Error', 'danger'); return false; } $this->setRedirect(Router::build('admin:categories'), 'Create success', 'success'); return true; }