We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38371
    • 42 Posts
    Hello to everyone,

    I am using MODx Revo 2.2.4.

    I have read the Doodles Tutorial and have successfully employed it to create an Extra already. However, this tutorial is about creating one Component menu item.

    I am currently creating an Extra with more than one menu items. And here is were I became a little confused.

    Say my namespace is "myns" and is under the directory: /modx/core/components/myns/

    I put my controllers under: myns/controllers/

    Now, for the first item:

    • I create an action with the controller set as: controllers/firstitem
    • and I create the file: controllers/firstitem/index.class.php

    For the second item:

    • I create an action with the controller set as: controllers/seconditem
    • and I create the file: controllers/seconditem/index.class.php

    When I select the first item from the Component menu it says that it cannot find the file:
    controllers/index.php

    So, it does not look in the subdirectory:
    firstitem

    but, only in the directory:
    controllers

    Could anyone explain to me how the loading process of 3rd party modActions takes place?

    In particular, how the paths and the class names should be declared?


    Thank you very much.

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

    [ed. note: leffyrant last edited this post 14 years, 1 month ago.]
    • discuss.answer
      • 38371
      • 42 Posts
      I have found a pattern that works for me, in MODx 2.2.4. As far as I can tell, this will be rendered as deprecated with the coming of MODx 2.3.

      The solution I found was to use the pattern described in the Doodles Tutorial multiple times. For example, say I want to create a menu item with two submenu items. So, we have:

      • menu item Parent,
      • menu item Child A and
      • menu item Child B.

      For the Parent:

      • action controller: controllers/index
      • controller class path: mycmp/controllers/index.class.php
      • controller class name: ControllersIndexManagerController

      Then, I have the method ControllersIndexManagerController#getDefaultController to return:
      "home"

      So, I create another class:

      • controller class path: mycmp/controllers/home.class.php
      • controller class name: MycmpHomeManagerController

      This is the class that all my logic for the CMP goes in. The first one is only there in order to reroute the request to this one. The rerouting takes place during the call of the "getDefaultController".

      Notice that this last class configuration will be called by default in MODx 2.3 and the previous one (index) will not be needed, as long as you change the action controller to "home" (but, this is all MODx 2.3).

      For Child A:

      • action controller: controllers/childa/index
      • controller class path: mycmp/controllers/childa/index.class.php
      • controller class name: ControllersChildaIndexManagerController

      Then, I have the method ControllersChildaIndexManagerController#getDefaultController to return:
      "home"
      again.

      So, I create another class:

      • controller class path: mycmp/controllers/childa/home.class.php
      • controller class name: MycmpChildaHomeManagerController

      The same goes for Child B.

      And that is the end of my custom solution. I do not know of any other way of creating a multi-level menu with actions pointing to controllers using the schema of MODx 2.3 in MODx 2.2.4.

      Please, if anyone else is using another method of action controller declaration, class path and class name configuration I would appreciate it if he/she would share it with me.