Well i have gone round and round and round.... so i thought i would ask... πŸ™‚

I have been trying to capture the user default_2fa value but all i get is an empty object

My code is:

  $config_item = [];
    $config_item = new ConfigItem();    
    $thestaff_id = (int) $staff->ht['staff_id'];    
    $user_default_2fa = ConfigItem::getConfigsByNamespace('staff.'.$thestaff_id, 'default_2fa');

             echo "<pre>";
              echo "hello";  //as a test output
              echo "<br>";              
              //echo $user_default_2fa;
              print_r($config_item);             
              exit;  

and my results are:

hello
ConfigItem Object
(
[ht] => Array
(
)

[dirty] => Array
    (
    )

[__new__] => 1
[__deleted__] => 
[__deferred__] => Array
    (
    )

)

Why cant i get any object values? I am working inside of profile.inc.php

The same command is in ajax.staff.php on line 317

if i call something in class ConfigItem which is in the same file class.config.php i get a valid object with data.

?? baffled

I may have to write a new class to get away from the section/namespace BS..

Here is what i am trying to do.. this is a new function i added

function getUserDefault2fa($staffid, $column)
    {
       if(!empty($staffid))
       {
           
        $sql="SELECT `value` FROM ".$this->table." WHERE $column = $staffid AND `key` = 'default_2fa'";
       
        if (($res=db_query($sql, false)) && db_num_rows($res))
        {
          return db_result($res);
        }
            
       }//close if not empty staffid
       
      return false;

    }//close function getUserDefault2fa

    I'm getting lost at the very beginning of your code.

    $config_item = []; creates an array
    $config_item = new ConfigItem(); creates an object

    Why do array and object have the same name?

      KevinTheJedi

      $config_item = new ConfigItem();

      gives me nothing in results

      hello
      ConfigItem Object
      (
      [ht] => Array
      (
      )

      [dirty] => Array
          (
          )
      
      [__new__] => 1
      [__deleted__] => 
      [__deferred__] => Array
          (
          )

      )

      i can get the whole config listing and then sift though that, but that is not what i want its a waste of resources. I just want the user data from the config table staff.1

      Is there a include i need to get access to that class


      UPDATE: ok looks like i actually had it last night and didnt realize it. I thought the staff default 2fa was the system default (thats how tired i was) so yeah i can get what i need using

      $_config = $staff->getConfig();

      ok perfect, i am so very close to finishing this.... another day or so to test it out and clean up the coding and i may have it to submit... πŸ™‚

        durangod2

        Right, doing new ConfigItem() creates a new object which would have nothing (as it’s new). I would recommend researching OOP (Object Oriented Programming) PHP if you want to deal with objects, etc.

        I do not and cannot provide any assistance with customizations. I will say there are easy, existing examples in the code that shows how to get the staff member and their profile settings, 2FA backend, etc.

        Cheers.

          KevinTheJedi

          This is one reason i only work with arrays in my projects, they are so much easier to work with. OOP is so 90's IMO but i see alot of code from 80's and 90's in the script. Example: table cellpadding cellspacing, hard to believe with all the updates that any of those still exist. I admit im not good at OOP, i dont write it and dont work with it alot. However, i am really good figuring out how stuff works (i have lots of experience in that) or i would have never gotten as far as i am on this mod. But some things yeah just drive me crazy, such as this.

          im like WTH... lol

          action="<?php echo sprintf('#staff/%d/2fa/configure/%s',
              $staff->getId(), $auth->getId()); ?>">

          which is

          #staff/1/2fa/configure/2fa-sms

          That is in a form action. Now i have used that sort of thing to call html modals in my own script, but the modal code is in the same file when i do it. I searched for #staff in the script and nothing anywhere other than the action calls to nowwhere. So somewhere i know it gets grabbed and converted during the $POST or $SESSION im guessing. This is the kind of stuff that makes me hate new coding practices (frameworks) also, there is no reason anyone should have to chase this down, it should be in the same file or have internal documentation to explain what is going on. Anyone with very basic php understanding can follow my scipt no problem as i document so many of my thoughts in there and what is happening.

          Yeah i know you cant help, most moderators cant so i do appreciate your suggestions so far, but i know you cant do it on a regular bases. I will figure out it.. πŸ™‚ All i have to do is get the configuration and verify of the phone number done and db recording done for the option and everything else should be done. Im hoping this is the last form stuff i have to do as everything else form is done. πŸ™‚

          One thing i would like to add here. One reason its taking me so long is that i want to follow the protocol established within the script for security reasons. I know there are "instances" i can use for processing data so i want to try to use those if i can. But then i also see files with the $sql statement right in the file and then im thinking wow how lazy is that person or maybe its just left over from the old days when we all use to do that, it was the standard back then. I get tempted to do it myself but i wont do it.

          πŸ™‚

          Write a Reply...