public function action_update($id = false) { if (!is_numeric($id)) { \Response::redirect('admin/attribute/list'); } // Get news item to edit if (!($item = Model_Attribute::find_one_by_id($id))) { \Response::redirect('admin/attribute/list'); } \View::set_global('title', 'Edit Attribute'); if (\Input::post()) { if (\Input::post('option_title', false)) { \Request::forge('admin/attribute/option/create')->set_method('POST')->execute()->response(); } $val = Model_Attribute::validate('update'); if ($val->run()) { // Get POST values $insert = \Input::post(); $item->set($insert); try { $item->save(); \Messages::success('Attribute successfully updated.'); \Response::redirect(\Input::post('exit', false) ? \Uri::create('admin/attribute/list/') : \Uri::admin('current')); } catch (\Database_Exception $e) { // show validation errors \Messages::error('<strong>There was an error while trying to update attribute</strong>'); // Uncomment lines below to show database errors //$errors = $e->getMessage(); //\Messages::error($errors); } } else { if ($val->error() != array()) { // show validation errors \Messages::error('<strong>There was an error while trying to update attribute</strong>'); foreach ($val->error() as $e) { \Messages::error($e->get_message()); } } } } $attribute = Model_Attribute::find_one_by_id($id); \Theme::instance()->set_partial('content', $this->view_dir . 'update')->set('attribute', $attribute); }