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

exists() public static method

Check if an item exists
public static exists ( integer $id ) : boolean
$id integer The id of the record to look for.
return boolean
    public static function exists($id)
    {
        return (bool) BackendModel::getContainer()->get('database')->getVar('SELECT 1
             FROM location AS i
             WHERE i.id = ? AND i.language = ?
             LIMIT 1', array((int) $id, BL::getWorkingLanguage()));
    }

Usage Example

Example #1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     $this->id = $this->getParameter('id', 'int');
     // does the item exists
     if ($this->id !== null && BackendLocationModel::exists($this->id)) {
         $this->header->addJS(FrontendLocationModel::getPathToMapStyles());
         parent::execute();
         // define Google Maps API key
         $apikey = $this->get('fork.settings')->get('Core', 'google_maps_key');
         // check Google Maps API key, otherwise redirect to settings
         if ($apikey === null) {
             $this->redirect(BackendModel::createURLForAction('Index', 'Settings'));
         }
         // add js
         $this->header->addJS('https://maps.googleapis.com/maps/api/js?key=' . $apikey, null, false, true, false);
         $this->loadData();
         $this->loadForm();
         $this->validateForm();
         $this->loadSettingsForm();
         $this->parse();
         $this->display();
     } else {
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing');
     }
 }
All Usage Examples Of Backend\Modules\Location\Engine\Model::exists