Joomla JInput获取函数不检索变量

时间:2014-08-27 18:15:21

标签: php joomla joomla2.5 joomla3.0

我又回来了另一个问题。

我正在尝试使用JInput从我的控制器中的表单POST获取一些值。问题是该方法不会返回任何值。问题是,当我尝试转储变量时,值存在于输入对象中。

这是一些代码。

控制器。

public function save($key = null, $urlVar = null){
    $result = parent::save($key, $urlVar);

    $request =  JFactory::getApplication()->input;
    $requestTitle = $request->get('title', 'default title','string');
    $requestAnnouncement = $request->get('announcement', 'default announcement', 'string');
    //$requestGroups = JRequest::getVar('groups', array(), 'post','array');

    //$recepients = $this->_getUserEmailsAndNamesFromGroup($requestGroups);
    ob_start();
    var_dump($request);
    $data = ob_get_clean();
    $mailSent = $this->_sendEmail(
                                    array(
                                        'title'=>$requestTitle, 
                                        'announce'=>$data), 

                                    array('email@gmail.com')
                                );

    if(!$result || !$mailSent){
        $this->setRedirect(
            JRoute::_(
                'index.php?option=' . $this->option . '&view=announces', false
            )
        );
    }

    return $result;
}

转储。

    object(JInput)#7 (4) {
  ["options":protected]=>
  array(0) {
  }
  ["filter":protected]=>
  object(JFilterInput)#8 (7) {
    ["tagsArray"]=>
    array(0) {
    }
    ["attrArray"]=>
    array(0) {
    }
    ["tagsMethod"]=>
    int(0)
    ["attrMethod"]=>
    int(0)
    ["xssAuto"]=>
    int(1)
    ["tagBlacklist"]=>
    array(22) {
      [0]=>
      string(6) "applet"
      [1]=>
      string(4) "body"
      [2]=>
      string(7) "bgsound"
      [3]=>
      string(4) "base"
      [4]=>
      string(8) "basefont"
      [5]=>
      string(5) "embed"
      [6]=>
      string(5) "frame"
      [7]=>
      string(8) "frameset"
      [8]=>
      string(4) "head"
      [9]=>
      string(4) "html"
      [10]=>
      string(2) "id"
      [11]=>
      string(6) "iframe"
      [12]=>
      string(6) "ilayer"
      [13]=>
      string(5) "layer"
      [14]=>
      string(4) "link"
      [15]=>
      string(4) "meta"
      [16]=>
      string(4) "name"
      [17]=>
      string(6) "object"
      [18]=>
      string(6) "script"
      [19]=>
      string(5) "style"
      [20]=>
      string(5) "title"
      [21]=>
      string(3) "xml"
    }
    ["attrBlacklist"]=>
    array(5) {
      [0]=>
      string(6) "action"
      [1]=>
      string(10) "background"
      [2]=>
      string(8) "codebase"
      [3]=>
      string(6) "dynsrc"
      [4]=>
      string(6) "lowsrc"
    }
  }
  ["data":protected]=>
  &array(9) {
    ["option"]=>
    string(15) "com_bettingtips"
    ["layout"]=>
    string(4) "edit"
    ["id"]=>
    string(1) "0"
    ["jform"]=>
    array(12) {
      ["title"]=>
      string(4) "p[lm"
      ["announcement"]=>
      string(4) "pplm"
      ["active"]=>
      string(1) "1"
      ["email_sent"]=>
      string(1) "1"
      ["name"]=>
      string(0) ""
      ["description"]=>
      string(0) ""
      ["published"]=>
      string(1) "1"
      ["created"]=>
      string(0) ""
      ["created_by"]=>
      string(1) "0"
      ["created_by_alias"]=>
      string(0) ""
      ["modified"]=>
      string(19) "0000-00-00 00:00:00"
      ["modified_by"]=>
      string(1) "0"
    }
    ["task"]=>
    string(5) "apply"
    ["524060c11890c5c4804226d12d9d0976"]=>
    string(1) "1"
    ["c310a666f2ba05c42e0e4fea2d8e84b0"]=>
    string(32) "52146dc34590ee3cb5c87307e3139a9a"
    ["toplevel_page_shortcodes-ultimate_last_tab"]=>
    string(1) "0"
    ["ja_elastica_tpl"]=>
    string(11) "ja_elastica"
  }
  ["inputs":protected]=>
  array(2) {
    ["cookie"]=>
    object(JInputCookie)#23 (4) {
      ["options":protected]=>
      array(0) {
      }
      ["filter":protected]=>
      object(JFilterInput)#8 (7) {
        ["tagsArray"]=>
        array(0) {
        }
        ["attrArray"]=>
        array(0) {
        }
        ["tagsMethod"]=>
        int(0)
        ["attrMethod"]=>
        int(0)
        ["xssAuto"]=>
        int(1)
        ["tagBlacklist"]=>
        array(22) {
          [0]=>
          string(6) "applet"
          [1]=>
          string(4) "body"
          [2]=>
          string(7) "bgsound"
          [3]=>
          string(4) "base"
          [4]=>
          string(8) "basefont"
          [5]=>
          string(5) "embed"
          [6]=>
          string(5) "frame"
          [7]=>
          string(8) "frameset"
          [8]=>
          string(4) "head"
          [9]=>
          string(4) "html"
          [10]=>
          string(2) "id"
          [11]=>
          string(6) "iframe"
          [12]=>
          string(6) "ilayer"
          [13]=>
          string(5) "layer"
          [14]=>
          string(4) "link"
          [15]=>
          string(4) "meta"
          [16]=>
          string(4) "name"
          [17]=>
          string(6) "object"
          [18]=>
          string(6) "script"
          [19]=>
          string(5) "style"
          [20]=>
          string(5) "title"
          [21]=>
          string(3) "xml"
        }
        ["attrBlacklist"]=>
        array(5) {
          [0]=>
          string(6) "action"
          [1]=>
          string(10) "background"
          [2]=>
          string(8) "codebase"
          [3]=>
          string(6) "dynsrc"
          [4]=>
          string(6) "lowsrc"
        }
      }
      ["data":protected]=>
      &array(3) {
        ["c310a666f2ba05c42e0e4fea2d8e84b0"]=>
        string(32) "52146dc34590ee3cb5c87307e3139a9a"
        ["toplevel_page_shortcodes-ultimate_last_tab"]=>
        string(1) "0"
        ["ja_elastica_tpl"]=>
        string(11) "ja_elastica"
      }
      ["inputs":protected]=>
      array(0) {
      }
    }
    ["post"]=>
    object(JInput)#421 (4) {
      ["options":protected]=>
      array(0) {
      }
      ["filter":protected]=>
      object(JFilterInput)#8 (7) {
        ["tagsArray"]=>
        array(0) {
        }
        ["attrArray"]=>
        array(0) {
        }
        ["tagsMethod"]=>
        int(0)
        ["attrMethod"]=>
        int(0)
        ["xssAuto"]=>
        int(1)
        ["tagBlacklist"]=>
        array(22) {
          [0]=>
          string(6) "applet"
          [1]=>
          string(4) "body"
          [2]=>
          string(7) "bgsound"
          [3]=>
          string(4) "base"
          [4]=>
          string(8) "basefont"
          [5]=>
          string(5) "embed"
          [6]=>
          string(5) "frame"
          [7]=>
          string(8) "frameset"
          [8]=>
          string(4) "head"
          [9]=>
          string(4) "html"
          [10]=>
          string(2) "id"
          [11]=>
          string(6) "iframe"
          [12]=>
          string(6) "ilayer"
          [13]=>
          string(5) "layer"
          [14]=>
          string(4) "link"
          [15]=>
          string(4) "meta"
          [16]=>
          string(4) "name"
          [17]=>
          string(6) "object"
          [18]=>
          string(6) "script"
          [19]=>
          string(5) "style"
          [20]=>
          string(5) "title"
          [21]=>
          string(3) "xml"
        }
        ["attrBlacklist"]=>
        array(5) {
          [0]=>
          string(6) "action"
          [1]=>
          string(10) "background"
          [2]=>
          string(8) "codebase"
          [3]=>
          string(6) "dynsrc"
          [4]=>
          string(6) "lowsrc"
        }
      }
      ["data":protected]=>
      array(3) {
        ["jform"]=>
        array(12) {
          ["title"]=>
          string(4) "p[lm"
          ["announcement"]=>
          string(4) "pplm"
          ["active"]=>
          string(1) "1"
          ["email_sent"]=>
          string(1) "1"
          ["name"]=>
          string(0) ""
          ["description"]=>
          string(0) ""
          ["published"]=>
          string(1) "1"
          ["created"]=>
          string(0) ""
          ["created_by"]=>
          string(1) "0"
          ["created_by_alias"]=>
          string(0) ""
          ["modified"]=>
          string(19) "0000-00-00 00:00:00"
          ["modified_by"]=>
          string(1) "0"
        }
        ["task"]=>
        string(14) "announce.apply"
        ["524060c11890c5c4804226d12d9d0976"]=>
        string(1) "1"
      }
      ["inputs":protected]=>
      array(0) {
      }
    }
  }
}

感谢。

3 个答案:

答案 0 :(得分:2)

看起来返回的数据被包装在jform - 数组中,对吗?所以阅读documentation看起来这可能是正确的方法:

$request =  JFactory::getApplication()->input;
$jform = $request->getArray(array(
    'jform' => array(
        'title' => 'string',
        'announcement' => 'string'
    )
));
$requestTitle=$jform['title']; 
$requestAnnouncement=$jform['announcement']; 

答案 1 :(得分:1)

现任"官方"使用Joomla核心从使用JForm对象和XML定义构造的表单加载POST请求的方式如下:

    $data = JFactory::getApplication()->input->post->get('jform', array(), 'array');

希望这有帮助。

答案 2 :(得分:-1)

我遇到了同样的问题,我决定使用已弃用的(但即使在joomla 3中仍然有效)

$requestTitle = JRequest::getVar('title','default_title');

等于$ requestAnnouncement