Php Joomla使用JInput检查空字符串
在这之后,为了清理我的输入,我想知道是否有一个空字符串被它覆盖了Php Joomla使用JInput检查空字符串,php,joomla,joomla2.5,Php,Joomla,Joomla2.5,在这之后,为了清理我的输入,我想知道是否有一个空字符串被它覆盖了 $jinput = JFactory::getApplication()->input; $this->name = $jinput->get('name', '', 'STRING'); 通常如果没有Joomla,我也会检查空字符串。比如: if (!empty($_POST['name'])) 查看JInput-get方法,我看到它检查它是否是isset: public function get($nam
$jinput = JFactory::getApplication()->input;
$this->name = $jinput->get('name', '', 'STRING');
通常如果没有Joomla,我也会检查空字符串。比如:
if (!empty($_POST['name']))
查看JInput-get方法,我看到它检查它是否是isset
:
public function get($name, $default = null, $filter = 'cmd')
{
if (isset($this->data[$name]))
{
return $this->filter->clean($this->data[$name], $filter);
}
return $default;
}
不同的是,isset
只检查null。但是,这是使用get方法的默认值。那么,如果我为第二个参数指定一个空字符串,这里是否包括我
$this->name = $jinput->get('name', '', 'STRING');
由Joomla来决定您的空字符串是否为有效值并不重要。他们必须使用
isset()
,因为如果他们使用empty()
,而您返回的'0'
是您期望的正常值,Joomla将返回默认值,而不是'0'
所以,他们使用isset()
检查变量是否设置是完全正常的,由您决定接受什么值
如果未设置该值,并且您将空字符串设置为第二个参数'
,则将返回一个空字符串
在您的示例中,将返回一个空字符串,这是预期的行为