Backend\Modules\Groups\Engine\Model::exists PHP Метод

exists() публичный статический Метод

Check if a group already exists
public static exists ( integer $id ) : boolean
$id integer The id to check upon.
Результат boolean
    public static function exists($id)
    {
        return (bool) BackendModel::getContainer()->get('database')->getVar('SELECT i.*
             FROM groups AS i
             WHERE i.id = ?', array((int) $id));
    }

Usage Example

Пример #1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     $this->id = $this->getParameter('id', 'int');
     // group exists and id is not null?
     if ($this->id !== null && BackendGroupsModel::exists($this->id)) {
         parent::execute();
         // get record
         $this->record = BackendGroupsModel::get($this->id);
         // delete group
         BackendGroupsModel::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['name']));
     } else {
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing');
     }
 }