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

exists() public static method

Does the item exist.
Deprecation: use doctrine instead
public static exists ( integer $id, boolean $activeOnly = true ) : boolean
$id integer The id of the record to check for existence.
$activeOnly boolean Only check in active items?
return boolean
    public static function exists($id, $activeOnly = true)
    {
        trigger_error('Backend\\Modules\\ContentBlocks\\Engine is deprecated.
             Switch to doctrine instead.', E_USER_DEPRECATED);
        $db = BackendModel::getContainer()->get('database');
        // if the item should also be active, there should be at least one row to return true
        if ((bool) $activeOnly) {
            return (bool) $db->getVar('SELECT 1
                 FROM content_blocks AS i
                 WHERE i.id = ? AND i.status = ? AND i.language = ?
                 LIMIT 1', array((int) $id, 'active', BL::getWorkingLanguage()));
        }
        // fallback, this doesn't take the active status in account
        return (bool) $db->getVar('SELECT 1
             FROM content_blocks AS i
             WHERE i.revision_id = ? AND i.language = ?
             LIMIT 1', array((int) $id, BL::getWorkingLanguage()));
    }

Usage Example

示例#1
0
文件: Edit.php 项目: bwgraves/forkcms
 /**
  * Execute the action
  */
 public function execute()
 {
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendContentBlocksModel::exists($this->id)) {
         parent::execute();
         $this->getData();
         $this->loadRevisions();
         $this->loadForm();
         $this->validateForm();
         $this->parse();
         $this->display();
     } else {
         // no item found, throw an exceptions, because somebody is f*****g with our url
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing');
     }
 }
All Usage Examples Of Backend\Modules\ContentBlocks\Engine\Model::exists