Ejemplo n.º 1
0
 /**
  * Update category SEO options
  * 
  * @param $id	= Category ID
  */
 public function action_update_seo($id = false)
 {
     if (!is_numeric($id)) {
         \Response::redirect('admin/product/category/list');
     }
     // Get news item to edit
     if (!($item = Model_Category::find_one_by_id($id))) {
         \Response::redirect('admin/product/category/list');
     }
     \View::set_global('title', 'Edit Meta Content');
     if (\Input::post()) {
         $val = Model_Category_Seo::validate('update', $item->id);
         // Get POST values
         $insert = \Input::post();
         if ($val->run($insert)) {
             // Update SEO database table
             $item_seo = Model_Category_Seo::find_one_by_content_id($item->id);
             if ($item_seo) {
                 $item_seo->set($insert);
             } else {
                 $item_seo = Model_Category_Seo::forge($insert);
             }
             try {
                 $item_seo->save();
                 \Messages::success('Meta content successfully updated.');
                 \Response::redirect(\Uri::admin('current'));
             } catch (\Database_Exception $e) {
                 // show validation errors
                 \Messages::error('<strong>There was an error while trying to update meta content</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 meta content</strong>');
                 foreach ($val->error() as $e) {
                     \Messages::error($e->get_message());
                 }
             }
         }
     }
     \Theme::instance()->set_partial('content', $this->view_dir . 'update_seo')->set('category', Model_Category::find_one_by_id($id));
 }