magento如何设置以及得到后台url

比如现在有个插件Zou_Test,我在后台想访问该插件的控制器,该如何访问呢?URL该怎么写?

1,现在config.xml里定义

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<admin>
<routers>
<ddsbase>
<use>admin</use>
<args>
<module>Zou_Test</module>
<frontName>test</frontName>
</args>
</ddsbase>
</routers>
</admin>
<adminhtml>

</adminhtml>

2,在app/code/local/Zou/Test/conreollers/Adminhtml建一个IndexController.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
class Zou_Test_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
{
public function reGenerateTokenAction(){
try {

$this->_getSession()->addSuccess($this->__('The product has been saved.'));
} catch (Mage_Core_Exception $e) {
$this->_getSession()->addError($e->getMessage());
} catch (Exception $e) {
$this->_getSession()->addError($e->getMessage());
}
$this->_redirect('*/*/');
}

}

3,此时在后台可以得到该控制器的url地址

1
echo Mage::helper('adminhtml')->getUrl('test/adminhtml_index/reGenerateToken');

或者要在Grid列表后Action加一个按钮的话:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$this->addColumn('action',
array(
'header' => Mage::helper('catalog')->__('Action'),
// 'width' => '50px',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('catalog')->__('Re-Generate Token'),
'url' => array(
'base'=>'test/adminhtml_index/reGenerateToken'
),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
));

 

4,这样就能正常访问了

坚持原创技术分享,您的支持将鼓励我继续创作!