custom_utils.php file is not able to get current user information

I created custom util file to create function and used language file to call that function.

Only problem I'm having is that it's not getting any information regarding current user. When I tried to print current user array to log file it shows like below:

07/06/16 16:28:54 [4504][-none-][FATAL]

As far as I know, it's not getting any userID as it shows [-none-] in log file.

Is this the Sugar Bug or I'm doing something wrong?

Parents
  • Hi Ricky,

    Can you please show your code. How you are retrieving current user.

    Where you create util  file. means location?

  • Hi Bhavesh Patel,

    Here is the location of the file:

    custom\Extension\application\Ext\Utils\test.php

    and here is the code in that file:

    <code>

    function test(){
       static $accounts = null;
       if(!$accounts){
       $db = DBManagerFactory::getInstance();

       $country = 'CA';

       $query = "select first_name, last_name from users where status = 'Active' and acl_role_set_id = 'f3be6dc6-4d77-74bb-30e8-5889899b' order by first_name";
       $result = $db->query($query, false);

       $accounts = array();
       $accounts['NA'] = 'No Filter';

       while (($row = $db->fetchByAssoc($result)) != null) {
       $accounts[$row['first_name'].'_'.$row['last_name']] = $row['first_name']. ' ' .$row['last_name'] ;
      }
      }

       return $accounts;
    }

    </code>

    In above code, I want to access logged in user's country. But below code shows no record, it prints blank in log file:

    <code>

    global $current_user;

    $GLOBALS['log']->fatal(print_r($current_user,1));

    </code>

    In log file, it prints as below:

    07/07/16 06:19:07 [4504][-none-][FATAL]

Reply
  • Hi Bhavesh Patel,

    Here is the location of the file:

    custom\Extension\application\Ext\Utils\test.php

    and here is the code in that file:

    <code>

    function test(){
       static $accounts = null;
       if(!$accounts){
       $db = DBManagerFactory::getInstance();

       $country = 'CA';

       $query = "select first_name, last_name from users where status = 'Active' and acl_role_set_id = 'f3be6dc6-4d77-74bb-30e8-5889899b' order by first_name";
       $result = $db->query($query, false);

       $accounts = array();
       $accounts['NA'] = 'No Filter';

       while (($row = $db->fetchByAssoc($result)) != null) {
       $accounts[$row['first_name'].'_'.$row['last_name']] = $row['first_name']. ' ' .$row['last_name'] ;
      }
      }

       return $accounts;
    }

    </code>

    In above code, I want to access logged in user's country. But below code shows no record, it prints blank in log file:

    <code>

    global $current_user;

    $GLOBALS['log']->fatal(print_r($current_user,1));

    </code>

    In log file, it prints as below:

    07/07/16 06:19:07 [4504][-none-][FATAL]

Children
No Data