从admin magento的其他控制器调用admin的控制器功能

时间:2016-01-05 11:04:32

标签: magento

我有一个控制器功能:

class Custom_OrderManager_Adminhtml_Sales_OrderinfoController extends Mage_Adminhtml_Controller_Action
{
    public function editInfoAction()
    {
        echo 'success';
    }
}

我想从其他控制器(adminhtml控制器)函数调用此函数。 我怎样才能做到这一点?我尝试过使用:

$controllerInstance = Mage::getControllerInstance('Custom_OrderManager_Adminhtml_Sales_OrderinfoController', $_REQUEST, new Mage_Core_Controller_Response_Http());
$controllerInstance->editInfoAction();

但是这给了我错误:

<b>Fatal error</b>:  Class 'Custom_OrderManager_Adminhtml_Sales_OrderinfoController' not found in <b>C:\xampp\htdocs\ssl\app\Mage.php</b> on line <b>520</b>

如果我做错了,请给我一些建议并纠正我。 提前谢谢。

2 个答案:

答案 0 :(得分:1)

你可以通过

来做到这一点
// require you file        
if(!class_exists('Custom_OrderManager_Adminhtml_Sales_OrderinfoController')) //in case the class already exists
{
    require_once('your class path');        
}

// instantiate your controller, using the `Mage:app()` object to grab the required request and response
$controller         = new Custom_OrderManager_Adminhtml_Sales_OrderinfoController(
                            Mage::app()->getRequest(),
                            Mage::app()->getResponse()
                        );        

// grab request and response object to manipulate as needed 
// (i.e. controller action expects post variables, etc.)

$request            = $controller->getRequest();
$response           = $controller->getResponse();

//manipulate things as per above

//call the action
$controller->editInfoAction();

答案 1 :(得分:0)

简单,自动加载器没有看到控制器,确保插件声明是正确的,如果它只是找不到类,我说清除配置缓存