[英]php passing arguments in constructor
Can anyone tell me why $Role
is being ignored? 谁能告诉我为什么$Role
被忽略?
I am trying to pass an argument and it is always getting a null
value, however, when I call the method the var_dump
shows that the $Role
is 2. 我试图传递一个参数,并且它始终获取null
值,但是,当我调用该方法时, var_dump
显示$Role
为2。
When I use the var_dump inside getListFromDB
the $Role
is being set to null. 当我在getListFromDB
使用var_dump时,将$Role
设置为null。
Method getListFromDB() 方法getListFromDB()
function getListFromDB($tableName, $orderBy = 'Description', $where = null, $Role = null) {
DO_Common::debugLevel(0);
if (empty($tableName) || empty($orderBy))
throw new Exception("tableName and orderBy cannot be left empty");
var_dump($Role);
if (!empty($Role))
{
echo "here";
if ($Role === 2)
{
if ($tableName == 'AssetTypes')
{
$params = array('tableName' => 'AssetTypes',
'orderBy' => $orderBy,
'whereAdd' => 'Restricted = 1');
}
var_dump($params);
}
else
{
$params = array('tableName' => $tableName,
'orderBy' => $orderBy);
var_dump($params);
}
}
else
{
$params = array('tableName' => $tableName,
'orderBy' => $orderBy);
//var_dump($params);
}
if (!empty($where) && $table != 'AssetTypes') {
if (strpos(strtolower($where), 'flag') === false)
$where .= " AND Flag != " . fDELETED;
$params += array('whereAdd' => $where);
}
return DO_Common::toAssocArray($params);
}
How the method is being called: 该方法的调用方式:
$AssetTypesOptions = getListFromDB('AssetTypes', $Role);
Is there something I am missing here? 我在这里缺少什么吗?
You should call it as the fourth argument, like so: 您应该将其称为第四个参数,如下所示:
getListFromDB("tablename", "some fancy description", "here", $Role);
I made them up obviously... 我显然把它们编起来了
$Role
是该函数的第四个参数,但是您将其作为第二个参数发送:
$AssetTypesOptions = getListFromDB('AssetTypes', 'Description', null, $Role);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.