コード例 #1
0
ファイル: Ajax.php プロジェクト: heimrichhannot/contao-ajax
 /**
  * Trigger a valid ajax action
  * @param $strGroup
  * @param $strAction
  * @param $objContext
  */
 public static function runActiveAction($strGroup, $strAction, $objContext)
 {
     if (Request::getInstance()->isXmlHttpRequest()) {
         /** @var AjaxAction */
         $objAction = Ajax::getActiveAction($strGroup, $strAction);
         if ($objAction === AJAX_ERROR_INVALID_GROUP) {
             header('HTTP/1.1 400 Bad Request');
             die('Invalid ajax group.');
         } else {
             if ($objAction === AJAX_ERROR_NO_AVAILABLE_ACTIONS) {
                 header('HTTP/1.1 400 Bad Request');
                 die('No available ajax actions within given group.');
             } else {
                 if ($objAction === AJAX_ERROR_INVALID_ACTION) {
                     header('HTTP/1.1 400 Bad Request');
                     die('Invalid ajax act.');
                 } else {
                     if ($objAction !== null) {
                         $objResponse = $objAction->call($objContext);
                         /** @var Response */
                         if ($objResponse instanceof Response) {
                             $objResponse->output();
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #2
0
 public function show()
 {
     global $objPage;
     $back = \Controller::generateFrontendUrl($objPage->row(), null, null, true);
     $blnAjax = false;
     $objModal = new Modal($this->objModal, $this->arrConfig);
     $objModal->setBackLink($back);
     $objResponse = new ResponseSuccess();
     $objResponse->setResult(new ResponseData($objModal->generate(), array('id' => $this->objModal->id)));
     $objResponse->setUrl(AjaxAction::removeAjaxParametersFromUrl(Request::getInstance()->getRequestUri()));
     return $objResponse;
 }
コード例 #3
0
 protected function getArguments()
 {
     $arrArgumentValues = array();
     $arrArguments = $this->arrAttributes['arguments'];
     $arrOptional = is_array($this->arrAttributes['optional']) ? $this->arrAttributes['optional'] : array();
     $strMethod = Request::getInstance()->getMethod();
     foreach ($arrArguments as $argument) {
         if (is_array($argument) || is_bool($argument)) {
             $arrArgumentValues[] = $argument;
             continue;
         }
         if (!in_array($argument, $arrOptional) && ($strMethod == 'POST' && !isset($_POST[$argument]) || $strMethod == 'GET' && !isset($_GET[$argument]))) {
             header('HTTP/1.1 400 Bad Request');
             die('Bad Request, missing argument ' . $argument);
         }
         $varValue = $strMethod == 'POST' ? Request::getPost($argument) : Request::getGet($argument);
         if ($varValue === 'true' || $varValue === 'false') {
             $varValue = filter_var($varValue, FILTER_VALIDATE_BOOLEAN);
         }
         $arrArgumentValues[] = $varValue;
     }
     return $arrArgumentValues;
 }