We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29333
    • 26 Posts
    Hello poeple !

    Please tell me what is the difference between a frontend mode and a backend mode execution of ModX.
    Oh, and I tried to make a snippet that displays a few rows of text something like:

    lalala
    lalala
    lalala

    lalala

    The code used was:
    $a = "lalala </br> lalala </br> lalala \n lalala </br>\n lalalala";
    return $a;


    I didn’t figure out how to make a line break.... It seems taht html-style </br> doesn’t work...

    It all started from a snippet to display the information returned by the getWebUserInfo() function
    The snippet is below:
    $out = 'Current User ID: ';
    $out .= $modx->getLoginUserID();
    $out .= ';</br> User Name: ';
    $out .= $modx->getLoginUserName();
    $out .= ';</br> User Type: ';
    $out .= $modx->getLoginUserType();
    $out .= "</br>\nUser Info: \n";
    $uinfo = var_export($modx->getwebUserInfo($modx->getLoginUserID()), true);
    $out .= $uinfo;
    return $out;


    The result is a horrible compact block... with no line breaks and no wide spaces...

    Any Ideas?

    And another thing: can the getLoginUserName() function return anything else besides "web" or "manager" strings ?
      Mosh-pit rules !!!
    • Frontend means what happens on the website, such as a web user login. Backend means what happens in the Manager, such as creating a new snippet.

      You mean more like this?

      $out = "Current User ID: ";
      $out .= $modx->getLoginUserID() . "<br />";
      $out .= "User Name: ";
      $out .= $modx->getLoginUserName() . "<br />";
      $out .= "User Type: ";
      $out .= $modx->getLoginUserType() . "<br />";
      $out .= "User Info:<br />";
      $uinfo = $modx->getwebUserInfo($modx->getLoginUserID());
      foreach($uinfo as $key=>$value) {
          $out .= "    " . ucwords($key) . " => " . $value . "<br />";
      }
      
      return $out;
      
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 34162
        • 1 Posts
        Quote from: tatacalu at Jun 21, 2005, 11:47 PM

        $a = "lalala </br> lalala </br> lalala \n lalala </br>\n lalalala";
        return $a;


        I didn’t figure out how to make a line break.... It seems taht html-style </br> doesn’t work...

        If that is actually what you are using, the problem is probably that the correct tag is
        , not </br>. Try reversing the position of your closing / and see if that helps.

        :)
          • 29333
          • 26 Posts
          Thanks... only one problem remains:

          foreach($uinfo as $key=>$value) {
              $out .= "    " . ucwords($key) . " => " . $value . "<br />";
          }


          This doesn’t work too good... The result is the following preview screen of the page:
          ? MODx Parse Error ?
          MODx encountered the following error while attempting to parse the requested resource:
          ? PHP Parse Error ?

          PHP error debug
          Error: Invalid argument supplied for foreach()
          Error type/ Nr.: Warning - 2
          File: C:\WebSite\modx\manager\includes\document.parser.class.inc.php(620) : eval()’d code
          Line: 9

          Parser timing
          MySQL: 0.0085 s s (7 Requests)
          PHP: 0.0449 s s
          Total: 0.0534 s s

          Ideas anyone ?
            Mosh-pit rules !!!
          • Probably not logged in. Need to put an "if" clause in there to make sure the getwebUserInfo call returns something!
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 29333
              • 26 Posts
              huh

              I reorganised the code: (only the part that interests the subject)
              if ($modx->getLoginUserType() == 'web')
              {
                $out .= "<br/>User Info: ";
                $inf = $modx->getwebUserInfo($modx->getLoginUserID());
                if (!is_null($inf))
                {
                  $uinfo = var_export($inf, true);
                  foreach($uinfo as $key=>$value)
                    {
                    $out .= "    " . ucwords($key) . " => " . $value . "<br />";
                    }
                 }
                else { $out .= '<br/> User info not available...';}
              }


              The result:
              ? MODx Parse Error ?
              MODx encountered the following error while attempting to parse the requested resource:
              ? PHP Parse Error ?

              PHP error debug
              Error: Invalid argument supplied for foreach()
              Error type/ Nr.: Warning - 2
              File: C:\WebSite\modx\manager\includes\document.parser.class.inc.php(620) : eval()’d code
              Line: 15

              Parser timing
              MySQL: 0.0138 s s (7 Requests)
              PHP: 0.0540 s s
              Total: 0.0677 s s

              I think the foreach is not written corectly. What do you think ??
              I thought of sth like:
              str_replace("\n",'<br/>',$uinfo);


              but that doesn’t work... i think that there must be another way to write that "\n"..... help !! smiley
                Mosh-pit rules !!!
              • Try this. The whole thing is wrapped in an "if" clause:

                if($uinfo = $modx->getwebUserInfo($modx->getLoginUserID())) {  // check for if logged in at all
                  if($modx->getLoginUserType() == 'web') {  // check for if is web user
                    $out = "Current User ID: ";
                    $out .= $uinfo['internalKey'] . "<br />";
                    $out .= "User Name: ";
                    $out .= $uinfo['username'] . "<br />";
                    $out .= "User Type: ";
                    $out .= $modx->getLoginUserType() . "<br />";
                    $out .= "User Info:<br />";
                    foreach($uinfo as $key=>$value) {
                    $out .= "    " . ucwords($key) . " => " . $value . "<br />";
                    }
                    return $out;
                  } else {        // user is not web user
                  $out = "User is not logged in as a web user";
                  return $out;
                  }
                } else {         // getwebUserInfo did not return anything
                $out = "User is not logged in.";
                return $out;
                }
                
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 29333
                  • 26 Posts
                  This doesn’t display anything grin

                  Thanks for your work, I’ll try to figure it out on my own.
                    Mosh-pit rules !!!
                    • 24253
                    • 125 Posts
                    Quote from: tatacalu at Jun 23, 2005, 11:35 AM

                    This doesn’t display anything? grin

                    Thanks for your work, I’ll try to figure it out on my own.


                    From the code, it seems at least something should be displayed, are you sure the page using this snippet is not cached?

                    Also this comparison:

                    $modx->getLoginUserType() == ’web’

                    is always false if ’web’ is of the string type?
                    guess, changing it to:

                    if($modx->getLoginUserType() == "web")

                    yield better resulst, but I’m not really a php coder so I may be wrong (C++ uses double quotes, so it seems reasonable php uses these syntax as well)

                    Happy excersising smiley


                      • 29333
                      • 26 Posts
                      OK, I found another solution: Writing the information returned by var_export into a file.

                      Hmm... but I noticed something weird: The string containing the State is one character shorter than it should. Instead of "Brasov" there says "Braso".
                      That also happens to the ZIP code....

                      Any suggestions ??

                      Oh and in the API quick reference I couldn’t find a function to return the basic paths, like the modx installation path. Is there such a function ?
                        Mosh-pit rules !!!