0

Can anyone tell me why $Role is being ignored?

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.

When I use the var_dump inside getListFromDB the $Role is being set to null.

Method 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?

0

2 Answers 2

1

$Role is the fourth argument for the function but you are sending it as the second argument:

$AssetTypesOptions = getListFromDB('AssetTypes', 'Description', null, $Role);
Sign up to request clarification or add additional context in comments.

1 Comment

Wow! Completely missed it! Thanks!
1

You should call it as the fourth argument, like so:

getListFromDB("tablename", "some fancy description", "here", $Role);

I made them up obviously...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.