<![CDATA[ Doodle tutorial part 3 - menu built problem - My Forums]]> https://forums.modx.com/thread/?thread=103461 <![CDATA[Doodle tutorial part 3 - menu built problem]]> https://forums.modx.com/thread/103461/doodle-tutorial-part-3---menu-built-problem#dis-post-556640 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]]>
theuros Feb 01, 2018, 08:30 PM https://forums.modx.com/thread/103461/doodle-tutorial-part-3---menu-built-problem#dis-post-556640
<![CDATA[Re: Doodle tutorial part 3 - menu built problem]]> https://forums.modx.com/thread/103461/doodle-tutorial-part-3---menu-built-problem#dis-post-556706
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');
]]>
BobRay Feb 04, 2018, 04:05 AM https://forums.modx.com/thread/103461/doodle-tutorial-part-3---menu-built-problem#dis-post-556706
<![CDATA[Re: Doodle tutorial part 3 - menu built problem]]> https://forums.modx.com/thread/103461/doodle-tutorial-part-3---menu-built-problem#dis-post-556696 theuros Feb 03, 2018, 09:33 AM https://forums.modx.com/thread/103461/doodle-tutorial-part-3---menu-built-problem#dis-post-556696 <![CDATA[Re: Doodle tutorial part 3 - menu built problem]]> https://forums.modx.com/thread/103461/doodle-tutorial-part-3---menu-built-problem#dis-post-556679
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.
]]>
BobRay Feb 02, 2018, 08:31 PM https://forums.modx.com/thread/103461/doodle-tutorial-part-3---menu-built-problem#dis-post-556679
<![CDATA[Re: Doodle tutorial part 3 - menu built problem (Best Answer)]]> https://forums.modx.com/thread/103461/doodle-tutorial-part-3---menu-built-problem#dis-post-556677
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]]>
theuros Feb 02, 2018, 08:06 PM https://forums.modx.com/thread/103461/doodle-tutorial-part-3---menu-built-problem#dis-post-556677
<![CDATA[Re: Doodle tutorial part 3 - menu built problem]]> https://forums.modx.com/thread/103461/doodle-tutorial-part-3---menu-built-problem#dis-post-556653
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/
]]>
BobRay Feb 01, 2018, 10:05 PM https://forums.modx.com/thread/103461/doodle-tutorial-part-3---menu-built-problem#dis-post-556653