We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32985
    • 2 Posts
    Good morning everyone!

    I am rather new to ModX, so this may be stupid but help me, please. I installed "Login" snippet and now I want to redirect all users that are not logged in from any page to one page (id :1), and redirect all users that are logged in from that page(id :1) to another (id :2). I thought that the most simple solution is to write a quick plug-in and set it "OnWebPageInit".

    $logged_out_doc_id=1;
    $logged_in_redirect_doc_id=2;
    if(!$modx->userLoggedIn()) {
           $modx->sendForward($logged_out_doc_id);
    }
    elseif($modx->documentIdentifier==$logged_out_doc_id) {
           $modx->sendForward($logged_in_redirect_doc_id);
    }
    


    But documentIdentifier (and the whole documentObject) seem to be NULL there. On what moment that objects are created? I looked up all available variables and now I use $modx->resourceIdentifier, but that doesn’t feel right.

    Two more minor questions:
    1) When i create snippet/plug-in there is "<?php" already in it (and no "?>"). Why?
    2) This is complex and I don’t know what details should I post here, but ModX seem to take loads of CPU on my local computer (not on my other server). I used standard apache2 + php5 + mysql on Ubuntu with a few additional modules for php (xdebug etc.). FreeBSD server works great. When i am in ModX manager on my local computer each ajax request eats about 30% or more of cpu and last from 1 to 5 sec. Web pages take about 300ms. All my other projects work great on the same computer.

    Thank you all in advance! (And sorry for my bad english)

    Edit:
    ModX: MODx Revolution 2.0.3-pl
    mysqld: Ver 5.1.41-3ubuntu12.6 for debian-linux-gnu on i486 ((Ubuntu))
    apache2: Apache/2.2.14 (Ubuntu)
    php: mod_php on apache2, Version 5.3.2-1ubuntu4.5
    OS: Ubuntu 10.04 with latest updates
    kernel: 2.6.32-25-generic

    Everything is standard for Ubuntu, nothing custom build here.
      • 19534
      • 183 Posts
      Hey XzKto

      Quote from: XzKto at Oct 07, 2010, 03:13 AM

      But documentIdentifier (and the whole documentObject) seem to be NULL there. On what moment that objects are created? I looked up all available variables and now I use $modx->resourceIdentifier, but that doesn’t feel right.

      $modx->documentIdentifier
      is deprecated, see: http://api.modxcms.com/modx/modX.html#$documentIdentifier

      Try using
      $modx->resource->get('id')


      or
      $modx->resourceIdentifier


      But I prefer the first one because it is more OO.

      Quote from: XzKto at Oct 07, 2010, 03:13 AM

      1) When i create snippet/plug-in there is "<?php" already in it (and no "?>"). Why?
      If your file contains only php code there’s no need to tell the parser when your code ends. You only need it if you want to tell the parse to stop interpreting the code as php. Take this for an example:

      <div>
      <?php 
      echo $content;
      ?>
      </div>
      


      Hope this helps
        Add-On to easily manage your multilingual sites: Babel
        • 32985
        • 2 Posts
        Thank you a lot! I was looking at ModX wiki and apparently they didnt upgrade for the latest ModX version (It is written "Modx versions: All"). And thank you for the link to ModX API, now everything is going to be much easier smiley. They really changed a lot in the new version.

        Edit: I used documentIdentifier in snippets a few times, it worked. Strange.