[英]Joomla JInput get function not retrieving variables
I comeback with another problem. 我回来了另一个问题。
I am trying to get some values from a form POST in my controller, using JInput. 我正在尝试使用JInput从控制器中的POST表单中获取一些值。 The problem is that the method doesn't return any value whatsoever.
问题在于该方法不会返回任何值。 The thing is that when i try to dump the variable, the values exist in the input object.
问题是,当我尝试转储变量时,值存在于输入对象中。
Here is some code. 这是一些代码。
The controller. 控制器。
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;
}
And the dump. 和垃圾场。
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) {
}
}
}
}
Thanks. 谢谢。
It looks like the data returned is wrapped in a jform - array, right? 看起来返回的数据包装在jform-数组中,对吗? So reading the documentation it looks like this might be the right approach:
因此,阅读文档似乎是正确的方法:
$request = JFactory::getApplication()->input;
$jform = $request->getArray(array(
'jform' => array(
'title' => 'string',
'announcement' => 'string'
)
));
$requestTitle=$jform['title'];
$requestAnnouncement=$jform['announcement'];
The current "official" way to load a POST request using Joomla core from a form constructed with the JForm object and an XML definition is like so: 当前的“正式”方式是使用Joomla核心从由JForm对象和XML定义构造的表单中加载POST请求,如下所示:
$data = JFactory::getApplication()->input->post->get('jform', array(), 'array');
Hope this helps. 希望这可以帮助。
I was facing the same problem and I decided to use the deprecated (but still working even in joomla 3) 我遇到了同样的问题,因此决定使用不推荐使用的方法(但即使在joomla 3中也可以使用)
$requestTitle = JRequest::getVar('title','default_title');
equaly for $requestAnnouncement 等于$ requestAnnouncement
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.