MODX 3 issue with menu item

I have a few plugins that do very tiny things, and rather than get involved with extjs, I’ve made them load into an iframe in the modx-content panel of the manager so I can use plain old HTML and PHP. It works great in MODX 2.8. In 3.0, however, I get the error “No action specified!” in the right panel.

I add a menu in the usual way, entering my custom namespace. For the action, I put the name of the PHP file that loads the iframe. So if I have the file “fixit.php” in the main folder of my namespace, which contains nothing but PHP output to make an iframe, I put “fixit” in the action field for the menu. This works in 2.8 and loads the code in that file into the manager panel. In 3.0, nothing happens. What has changed in the way this works in 3.0?

I believe you have to use a controller now.

Name the file fixit.class.php and put it in the folder core/componets/yournamespace/controllers/.
The name of the class has to be Namespace + Action + ManagerController

In the simplest case, you should be able to just return some html markup in the process() function.

<?php
use MODX\Revolution\modManagerController;

class YournamespaceFixitManagerController extends modManagerController
{
    public function checkPermissions()
    {
        return true;
    }

    public function process(array $scriptProperties = [])
    {
        return '<div>some html</div>';
    }

    public function getPageTitle()
    { 
        return 'Fixit';
    }

    public function loadCustomCssJs()
    {
    }

    public function getTemplateFile()
    {
        return '';
    }
}

I figured it was something like that. I got as far as making a fixit.class.php file, but didn’t know what to put in it. I’ll give this a try.

Works! Thanks so much.

Another (simpler) way to go is to just create a core/components/yourcomponent/index.php file.

In the menu item, put just index in the “Action” field and fill in the namespace (and optionally, any permissions you want).

In that index.php file, you can just return the content you want.

You can also do something like this:

return $modx->runSnippet('MySnippet')

or

return $modx->runSnippet('MySnippet', $scriptProperties);

This is how SiteCheck works, and it runs equally well in MODX 2 and MODX 3.

[UPDATE] This method does not work in MODX 3. The method described by halftrainedharry will work in both MODX 2 and MODX 3, so it’s a much better approach.

I thought I had tried that and it didn’t work. Maybe I didn’t do it correctly. Will try again.

I also tried what Bob wrote, but it didn’t work for me either.

Sorry, my bad. I’ve been working on converting SiteCheck for both MODX 2 and MODX 3. I had renamed the controllers directory and controller file and it still ran fine with the setup I described above.

What I didn’t notice was that I was running it in MODX 2. :woozy_face:

The controller directory and file are definitely necessary in MODX 3.

The good news is that using the controller directory and file appears to work in both MODX 2 and MODX 3, without the index.php file I described above.