Backend\Modules\ContentBlocks\Engine\Model::delete PHP Method

delete() public static method

Delete an item.
Deprecation: use doctrine instead
public static delete ( integer $id )
$id integer The id of the record to delete.
    public static function delete($id)
    {
        trigger_error('Backend\\Modules\\ContentBlocks\\Engine is deprecated.
             Switch to doctrine instead.', E_USER_DEPRECATED);
        // recast id
        $id = (int) $id;
        // get item
        $item = self::get($id);
        // delete extra and pages_blocks
        BackendModel::deleteExtraById($item['extra_id']);
        // delete the content_block
        BackendModel::getContainer()->get('database')->delete('content_blocks', 'id = ? AND language = ?', [$id, BL::getWorkingLanguage()]);
    }

Usage Example

Example #1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendContentBlocksModel::exists($this->id)) {
         parent::execute();
         $this->record = (array) BackendContentBlocksModel::get($this->id);
         // delete item
         BackendContentBlocksModel::delete($this->id);
         // trigger event
         BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id));
         // item was deleted, so redirect
         $this->redirect(BackendModel::createURLForAction('Index') . '&report=deleted&var=' . urlencode($this->record['title']));
     } else {
         // no item found, redirect to the overview with an error
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing');
     }
 }