We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29796
    • 91 Posts
    I'm helping a friend who went through doodles tutorial and had problems with last part of the tutorial. I looked at it but can't find what is wrong. Build script works fine, but something is wrong with menu generation. When you install created extra and try to click on extras / doodle link you get redirected to:
    http://localhost/modxtest/manager/?a=2 instead of http://localhost/modxtest/manager/?a=index&namespace=doodles (if you corrent the path manualy then it works fine)

    I checked the menu how is made and is not as it should be.

    On dev version Action is set to "index", on installed one is set to 2
    Also namespace is wrong. On dev version is "doodles" but on installed one is "core"

    My "menu" code inside build.transport.php looks like:
    $modx->log(modX::LOG_LEVEL_INFO,'Packaging in menu...');
    $menu = include $sources['data'].'transport.menu.php';
    if (empty($menu)) $modx->log(modX::LOG_LEVEL_ERROR,'Could not package in menu.');
    $vehicle= $builder->createVehicle($menu,array (
        xPDOTransport::PRESERVE_KEYS => true,
        xPDOTransport::UPDATE_OBJECT => true,
        xPDOTransport::UNIQUE_KEY => 'text',
        xPDOTransport::RELATED_OBJECTS => true,
        xPDOTransport::RELATED_OBJECT_ATTRIBUTES => array (
            'Action' => array (
                xPDOTransport::PRESERVE_KEYS => false,
                xPDOTransport::UPDATE_OBJECT => true,
                xPDOTransport::UNIQUE_KEY => array ('namespace','controller'),
            ),
        ),
    ));
    


    And my transport.menu.php is:

    <?php
    $action= $modx->newObject('modAction');
    $action->fromArray(array(
        'id' => 1,
        'namespace' => 'doodles',
        'parent' => 0,
        'controller' => 'index',
        'haslayout' => true,
        'lang_topics' => 'doodles:default',
        'assets' => '',
    ),'',true,true);
     
    $menu= $modx->newObject('modMenu');
    $menu->fromArray(array(
        'text' => 'doodles',
        'parent' => 'components',
        'description' => 'doodles.desc',
        'icon' => 'images/icons/plugin.gif',
        'menuindex' => 0,
        'params' => '',
        'handler' => '',
    ),'',true,true);
    $menu->addOne($action);
    unset($menus);
     
    return $menu;
    


    I know that in the past for action a numeric id value was used instead of namespaces like now. I asked about it on slack and markh replied with:

    If you want to use the new style in that build, drop the $action and set the namespace + action as string on the menu

    :) I don't have a clue what he ment.

    I'm looking through various extras on github to find how to define that in different way but I didn't had any luck yet.

    Thanx for any info

    This question has been answered by theuros. See the first response.

      • 3749
      • 24,544 Posts
      The Doodles tutorial is out of date since it uses the old style where there is a separate action record for each menu item. This should still work, but you need 'namespace' and 'action' fields on the modMenu object. I think you may also need a resolver to set the action ID correctly after installation, but I'm not sure.

      Mark was referring to the new method (since MODX 2.2) where the string in the modMenu's action field is sent to the in the URL as the 'a' parameter, and the file executed is based on the namespace's core path + that string. I'm not sure that would all fly with your current build files. I think it would work, but I'm not sure.

      Tips on the new method:

      https://bobsguides.com/blog.html/2014/03/28/modx-2.2-cmps-an-anatomy-lesson/

      https://www.markhamstra.com/xpdo/2012/getting-started-with-class-based-processors-2.2/
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
      • discuss.answer
        • 29796
        • 91 Posts
        Hi,

        Thanx for reply. I managed to make it work. I had to remove $action as "markh" told me and add namespace and action in menu object as "markh" already told me smiley

        My transport.menu.php now looks like
        <?php
        $menu= $modx->newObject('modMenu');
        $menu->fromArray(array(
            'text' => 'doodles',
            'parent' => 'components',
            'description' => 'doodles.desc',
            'icon' => 'images/icons/plugin.gif',
            'menuindex' => 0,
            'params' => '',
            'handler' => '',
            'namespace' => 'doodles',
            'action' => 'index',
        ),'',true,true);
        
        unset($menus); 
        return $menu;
        


        and works as it should.

        I just need to check that unset($menus); why is there. Also installing my doodle gives me some "PHP notice: Undefined offset: 2" which I need to find out what cause them.

        Console running...
        Attempting to install package with signature: doodles-1.0-beta4
        Package found...now preparing to install.
        Grabbing package workspace...
        PHP notice: Undefined offset: 2
        Workspace environment initiated, now installing package...
        Created table `modx_doodles` SQL: CREATE TABLE `modx_doodles` (`id` INTEGER unsigned NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL DEFAULT '', `description` TEXT NOT NULL, `createdon` DATETIME NULL, `createdby` INT(10) unsigned NOT NULL DEFAULT '0', `editedon` DATETIME NULL, `editedby` INT(10) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`id`)) ENGINE=MyISAM
        Successfully installed package doodles-1.0-beta4
        PHP notice: Undefined offset: 2
        


        Thank you
          • 3749
          • 24,544 Posts
          I think the unset is just there to save memory. I could be wrong.

          You probably know this, but the "Undefined offset" notice means the install script is referencing some array with that offset

          $arrayName[2];


          when there is no array member with that index. One way it happens is when you use a loop with an index where you start with 1 and the array's actual index starts at 0.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 29796
            • 91 Posts
            yea I know why it happens, I just need to figure it out where is the cause. Is there a better way to test the install script without actually install it? I mean ... now I have to build the package first, uninstall previous version and then install a new one and check if it's error / notice free.
              • 3749
              • 24,544 Posts
              There's no easy way that I know of. You could step through the install script with a debugger and a breakpoint on the first line of your script, but configuring the debug platform might take even longer than finding the problem on your own.

              Remember that you can put log statements in the script, so you may be able to do a binary search for the problem. Put the code below about halfway through the build script. If it shows up before the error message, the problem is in the second half, if not it's in the first half. Then move the line to the middle of the half with the problem, and so on.

              $modx->log(modX::LOG_LEVEL_INFO, 'Made it to here');
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting