We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45634
    • 23 Posts
    I'm writing some custom manager pages, and I would like to link from one directly to the other.

    When you add an action in the system, you specify a Controller and a Namespace. This is then given an ID, which becomes the URL. eg /manager/?a=78

    Basically, given a Namespace and Controller, in PHP how can I get the action ID so I can construct a link to it?

    I notice there is an "modAction" table - can I just look up the ID from that, or is there a better way?

    Thanks,
    James

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

      • 18373 ☆ A M B ☆
      • 3,141 Posts
      In PHP you should be able of doing this:

      $a = $modx->actions['mynamespace:foo/bar']


      but keep in mind that in 2.3 actions are deprecated, and you can instead link to /manager/?a=foo/bar&namespace=mynamespace
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
      • discuss.answer
        • 45634
        • 23 Posts
        So I'm on 2.2 ... but I don't have $modx->actions? I did however find this:

        	public function getURL($controller) {
        		foreach($this->modx->actionMap as $action) {
        			if ($action['namespace'] == 'whisky' && $action['controller'] == $controller) {
        				return '/manager/?a='.$action['id'];
        			}
        		}
        	}


        Which seems to work ... thanks for pointing me in the right direction!
          • 18373 ☆ A M B ☆
          • 3,141 Posts
          Oops, I meant actionMap. I mixed up the javascript and php APIs there, but glad you found it smiley
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
            • 3749
            • 24,544 Posts
            In theory, this would be all you'd need:

            $actionId = $modx->actions[$controller . '/' , $namespace]
            return '/manager/?a='.$actionId;
            
            


            IIRC, I've had it fail, however.

            This should always work:

            $actions = $this->modx->request->getAllActionIDs('core');
            $actionId = $actions[$controller . '/' , $namespace];
            return '/manager/?a='.$actionId;
            



            I think this would be faster than crawling through all the actions.
              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