VirtualPage::isActive PHP Method

isActive() public method

If no parameter is passed, then return active page mode.
public isActive ( string $mode = null ) : boolean | string
$mode string Optionally ask for specific mode
return boolean | string
    public function isActive($mode = null)
    {
        if ($mode !== null && isset($_GET[$this->name])) {
            return $_GET[$this->name] == $mode;
        }
        return isset($_GET[$this->name]) ? $_GET[$this->name] : false;
    }

Usage Example

コード例 #1
0
ファイル: CRUD.php プロジェクト: atk4/atk4
 /**
  * Returns if CRUD is in editing mode or not. It's preferable over
  * checking if($grid->form).
  *
  * @param string $mode Specify which editing mode you expect
  *
  * @return bool true if editing.
  */
 public function isEditing($mode = null)
 {
     $page_mode = $this->virtual_page->isActive();
     // Requested edit, but not allowed
     if ($page_mode == 'edit' && !$this->allow_edit) {
         throw $this->exception('Editing is not allowed');
     }
     // Requested add but not allowed
     if ($page_mode == 'add' && !$this->allow_add) {
         throw $this->exception('Adding is not allowed');
     }
     // Request matched argument exactly
     if (!is_null($mode)) {
         return $mode === $page_mode;
     }
     // Argument was blank, then edit/add is OK
     return (bool) $page_mode;
 }