让 jqgrid 动作助手开始工作

发布于 2024-08-19 16:35:38 字数 2875 浏览 5 评论 0原文

经过几次搜索后,我发现了一个 jqgrid 操作助手,我可以包含到我的 Zend MVC 中。 但是,下载源代码并尝试使用它后,我收到此错误

Fatal error: Call to a member function getActionController() on a non-object in
.....
\Controller\Action\HelperBroker.php on line 299

这是助手的摘录

class My_Helper_jqgrid extends Zend_Controller_Action_Helper_Abstract {
    /**
     * Instance of the config file.
     *
     * @var Zend_Config_Ini
     */
    protected $_config = null;

    /**
     * The instance of the database
     *
     * @var Zend_Db_Adapter_Abstract
     */
    protected $_db = null;

    /**
     * The provided view
     * 
     * @var Zend_View_Interface
     */
    protected $_view = null;

    /**
     * The options provided to this helper
     * 
     * @var array
     */
    protected $_options = array();

    /**
     * @var Zend_Loader_PluginLoader
     */
    public $_pluginLoader;  

    public function __construct(Zend_View_Interface $view = null, array $options = array()){
        //$this->_db = Zend_Registry::getInstance()->get("db");         
        $this->_db = 'mato';            
        $this->_pluginLoader = new Zend_Loader_PluginLoader();
        $this->_view = $view;           
        $this->_options = $options;             
    }

    /**
     * Strategy pattern: call helper as broker method
     * 
     * @param string | Zend_Db_Table_Select $sql
     * @param string | array $columns
     */
    public function direct($sql, $columns = "*", $tableId = "id", array $options = array()) {

        Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender();
        Zend_Controller_Action_HelperBroker::getStaticHelper('layout')->disableLayout();

        $this->_options = $options;     
        $page = $this->getRequest()->getParam("page", 1); // get the requested page 
        $rows = $this->getRequest()->getParam("rows", 20); // get how many rows we want to have into the grid 
        $sidx = $this->getRequest()->getParam("sidx", $tableId); // get index row - i.e. user click to sort 
        $sord = $this->getRequest()->getParam("sord", "asc") == "desc" ? "DESC" : "ASC"; // get the direction
        $response = new stdClass(); // The response object which will be translated into a json object
        ...............
        ................
        return json_encode($response);      
    }   
}

在我的控制器中

print $this->_helper->Jqgrid("SELECT * FROM artist", 
        array("artist_code","artist_name","artist_album"), "id");

在我的引导程序中

Zend_Controller_Action_HelperBroker::addPath(
        APPLICATION_PATH . "/controllers/helpers", "My_Helper");

我缺少什么?

After a few searches I came across a jqgrid action helper that I could include into my Zend MVC.
However after downloading the source and trying to use it I get this error

Fatal error: Call to a member function getActionController() on a non-object in
.....
\Controller\Action\HelperBroker.php on line 299

Here is an excerpt of the helper

class My_Helper_jqgrid extends Zend_Controller_Action_Helper_Abstract {
    /**
     * Instance of the config file.
     *
     * @var Zend_Config_Ini
     */
    protected $_config = null;

    /**
     * The instance of the database
     *
     * @var Zend_Db_Adapter_Abstract
     */
    protected $_db = null;

    /**
     * The provided view
     * 
     * @var Zend_View_Interface
     */
    protected $_view = null;

    /**
     * The options provided to this helper
     * 
     * @var array
     */
    protected $_options = array();

    /**
     * @var Zend_Loader_PluginLoader
     */
    public $_pluginLoader;  

    public function __construct(Zend_View_Interface $view = null, array $options = array()){
        //$this->_db = Zend_Registry::getInstance()->get("db");         
        $this->_db = 'mato';            
        $this->_pluginLoader = new Zend_Loader_PluginLoader();
        $this->_view = $view;           
        $this->_options = $options;             
    }

    /**
     * Strategy pattern: call helper as broker method
     * 
     * @param string | Zend_Db_Table_Select $sql
     * @param string | array $columns
     */
    public function direct($sql, $columns = "*", $tableId = "id", array $options = array()) {

        Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender();
        Zend_Controller_Action_HelperBroker::getStaticHelper('layout')->disableLayout();

        $this->_options = $options;     
        $page = $this->getRequest()->getParam("page", 1); // get the requested page 
        $rows = $this->getRequest()->getParam("rows", 20); // get how many rows we want to have into the grid 
        $sidx = $this->getRequest()->getParam("sidx", $tableId); // get index row - i.e. user click to sort 
        $sord = $this->getRequest()->getParam("sord", "asc") == "desc" ? "DESC" : "ASC"; // get the direction
        $response = new stdClass(); // The response object which will be translated into a json object
        ...............
        ................
        return json_encode($response);      
    }   
}

In my controller

print $this->_helper->Jqgrid("SELECT * FROM artist", 
        array("artist_code","artist_name","artist_album"), "id");

In my bootstrap

Zend_Controller_Action_HelperBroker::addPath(
        APPLICATION_PATH . "/controllers/helpers", "My_Helper");

What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乱世争霸 2024-08-26 16:35:38

检查这个:http://zendframework.com/issues/browse/ZF-7027

我刚刚在谷歌上搜索了您的错误,所以我不确定上面的链接是否适用。

Check this: http://zendframework.com/issues/browse/ZF-7027

I just googled for your error so I'm not sure if the link above applies.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文