3

Basically in trying to create an inbox message which "read details" should redirect the user to a custom controller, however i can see the desired url in the browser for a second and then it redirects to the dashboard; this is how, currently, im trying to achieve that:

    $myId = $myJson['id'];
    $title = "Title of my notice";
    $description = $myJson['text'];
    $url= Mage::helper("adminhtml")->getUrl('My_Module/Controller/index', array('id' => $myId));

    $sendingMessage = Mage::getModel('adminnotification/inbox')->addNotice($title,$description,$url);

The code above successfully adds the message to the inbox, however as i said before, i can see the desired URL in the browser before it gets redirected to the dashboard.

I'm accessing the same controller from another one and it does it as expected, the one that is actually working is a Grid and it looks something like this:

$this->addColumn('action',
array(
          'header' => __('Answer'),
          'width' => '100',
          'type' => 'action',
          'getter' => 'getId',
          'actions' => array(
                 array(
                      'caption' => __('Answer'),
                      'url' => array('base'=> '*/Controller'),
                      'field' => 'id'
                    )),
          'filter' => false,
          'sortable' => false,
          'index' => 'stores',
          'is_system' => true,
));

So, am i missing something here ?

BTW, is there any way to make the "read details" link to open in the same page instead of a new tab?

==================================================================

UPDATE

Disabling the "Add Secret Key to URLs" in the security options allowed me get it work, however i would like to make use of the secret keys.

The URLs i'm generating in the first code block actually have a key/value in the URLs, they look something like this:

https://example.com/index.php/mymodule/Controller/index/id/3963566814/key/f84701848a22d2ef36022accdb2a6a69/
Alana Storm
  • 164,128
  • 91
  • 395
  • 599
VdeVentura
  • 2,041
  • 2
  • 15
  • 16

1 Answers1

3

It looks like you're trying to generate an admin URL. In modern versions of Magento, admin urls must use the adminhtml front name, using the Magento Front Name Sharing technique (described in this article). That's must as in if you don't, the URLs won't work. Magento removed the ability to create non-adminhtml URLs in the backend.

Second, here's where Magento generates the secret keys

#File: app/code/core/Mage/Adminhtml/Model/Url.php
public function getSecretKey($controller = null, $action = null)
{
    $salt = Mage::getSingleton('core/session')->getFormKey();

    $p = explode('/', trim($this->getRequest()->getOriginalPathInfo(), '/'));
    if (!$controller) {
        $controller = !empty($p[1]) ? $p[1] : $this->getRequest()->getControllerName();
    }
    if (!$action) {
        $action = !empty($p[2]) ? $p[2] : $this->getRequest()->getActionName();
    }

    $secret = $controller . $action . $salt;
    return Mage::helper('core')->getHash($secret);
}

and here's where it validates the secret key

#File: app/code/core/Mage/Adminhtml/Controller/Action.php
protected function _validateSecretKey()
{
    if (is_array($this->_publicActions) && in_array($this->getRequest()->getActionName(), $this->_publicActions)) {
        return true;
    }

    if (!($secretKey = $this->getRequest()->getParam(Mage_Adminhtml_Model_Url::SECRET_KEY_PARAM_NAME, null))
        || $secretKey != Mage::getSingleton('adminhtml/url')->getSecretKey()) {
        return false;
    }
    return true;
}

Compare the pre/post hash values of $secret to see why Magento's generating the incorrect key on your page.

Alana Storm
  • 164,128
  • 91
  • 395
  • 599
  • ok, let me see if i got your article right, among others (for example the way the router is declared in my config.xml), my controllers should start with adminhtml_ ? – VdeVentura Mar 04 '16 at 19:33