Backend\Modules\Blog\Engine\Model::updateCategory PHP Method

updateCategory() public static method

Update an existing category
public static updateCategory ( array $item, array $meta = null ) : integer
$item array The new data.
$meta array The new meta-data.
return integer
    public static function updateCategory(array $item, $meta = null)
    {
        // get db
        $db = BackendModel::getContainer()->get('database');
        // update category
        $updated = $db->update('blog_categories', $item, 'id = ?', array((int) $item['id']));
        // meta passed?
        if ($meta !== null) {
            // get current category
            $category = self::getCategory($item['id']);
            // update the meta
            $db->update('meta', $meta, 'id = ?', array((int) $category['meta_id']));
        }
        return $updated;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         // validate meta
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = $this->id;
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['meta_id'] = $this->meta->save(true);
             // update the item
             BackendBlogModel::updateCategory($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit_category', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('Categories') . '&report=edited-category&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']);
         }
     }
 }