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

getCategory() public static method

Get all data for a given id
public static getCategory ( integer $id ) : array
$id integer The id of the category to fetch.
return array
    public static function getCategory($id)
    {
        return (array) BackendModel::getContainer()->get('database')->getRecord('SELECT i.*
             FROM blog_categories AS i
             WHERE i.id = ? AND i.language = ?', array((int) $id, BL::getWorkingLanguage()));
    }

Usage Example

Beispiel #1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendBlogModel::existsCategory($this->id)) {
         // get data
         $this->record = (array) BackendBlogModel::getCategory($this->id);
         // allowed to delete the category?
         if (BackendBlogModel::deleteCategoryAllowed($this->id)) {
             // call parent, this will probably add some general CSS/JS or other required files
             parent::execute();
             // delete item
             BackendBlogModel::deleteCategory($this->id);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_delete_category', array('id' => $this->id));
             // category was deleted, so redirect
             $this->redirect(BackendModel::createURLForAction('Categories') . '&report=deleted-category&var=' . rawurlencode($this->record['title']));
         } else {
             $this->redirect(BackendModel::createURLForAction('Categories') . '&error=delete-category-not-allowed&var=' . rawurlencode($this->record['title']));
         }
     } else {
         // something went wrong
         $this->redirect(BackendModel::createURLForAction('Categories') . '&error=non-existing');
     }
 }
All Usage Examples Of Backend\Modules\Blog\Engine\Model::getCategory