Joomla 2.5组件:无效的控制器:name ='',format ='raw'

时间:2013-09-06 19:51:32

标签: components joomla2.5

我正在开发一个集成jqGrid的自定义joomla 2.5组件。

我设置一个控制器任务来处理(更新mysql记录)从jqGrid postData发送的数据

 var grid = jQuery(\"#list\");
            grid.jqGrid({
        onSelectRow: function(id){
            $('#list').editRow(id, true); 
        },
                url: '/index.php?option=com_nutraidev&view=products&format=raw',
                datatype: 'json',
                mtype: 'GET',
                colNames: [...],
                rowNum: 25,
                rowList: [5, 10, 20, 50],
                height: 'auto',
                pager: '#pager',
                loadonce: true,
                sortname: 'ID',
                viewrecords: true,
                direction:'RTL',
                autowidth: true,
                sortorder: \"desc\",
                caption: 'abc',
                width: '70%',
        editurl:'/index.php?option=com_nutraidev&view=products&task=Products.save&token=". JUtility::getToken() ."=1',   
                postData: {'code':\" \",....},
.....

这是发出请求的网址

/index.php?option=com_nutraidev&view=products&task=Products.save&token=". JUtility::getToken() ."=1&format=raw

我得到:

 error 500
    Invalid controller: name='products', format='raw'

使用实际令牌从浏览器中尝试了它 - 结果相同。

这是我的代码的重要部分:

com_nutraidev               - 控制器                         - products.php

require_once JPATH_COMPONENT.'/controller.php';

    class NutraidevControllerProducts extends NutraidevController
    {

        public function &getModel($name = 'Products', $prefix = 'NutraidevModel')
        {
            $model = parent::getModel($name, $prefix, array('ignore_request' => true));
            return $model;
        }


        public function save()
        {
            // Check for request forgeries.
            JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));

            // Initialise variables.
            $app    = JFactory::getApplication();
            $model = $this->getModel('Products', 'NutraidevModel');
            $data = JRequest::get('get');

            // Attempt to save the data.
            $return = $model->updItem($data);

            }

    }

com_nutraidev              - 楷模                         - products.php

jimport('joomla.application.component.modellist');

class NutraidevModelProducts extends JModelList {

    public function __construct($config = array()) {
        parent::__construct($config);
    }

      public function updItem($data)
        {
        // set the variables from the passed data
        $code = $data['code'];
        $name = $data['name'];

        // set the data into a query to update the record
                $db   = $this->getDbo();
                $query  = $db->getQuery(true);
                $query->clear();
                $query->update(' #__product ');
                $query->set(' name = '.$db->Quote($name) );
                $query->where(' code = ' . (int) $code );

                $db->setQuery((string)$query);

        if (!$db->query()) {
            JError::raiseError(500, $db->getErrorMsg());
                return false;
        } else {
                return true;
                }
        }
}

com_nutraidev    - 意见    - 产品    - view.raw.php

 jimport('joomla.application.component.view');

    class NutraidevViewProducts extends JView
    {

/ **      *显示视图      * /     公共函数显示($ tpl = null)     {         $ app = JFactory :: getApplication();

    $document = JFactory::getDocument();
    // Get data from the model
    $items = $this->get('Items');

    $this->state        = $this->get('State');

    $this->params       = $app->getParams('com_nutraidev');

    // Check for errors.
    if (count($errors = $this->get('Errors'))) {;
        throw new Exception(implode("\n", $errors));
    }

    // Assign data to the view
    $response->page = 1;//JRequest::getVar('page');
    $response->total = 1;//JRequest::getVar('total');
    $response->records = count($items);
    $i=0;

     for ($i = 0; $i < count($items); ++$i) {
         $response->rows[$i]['id'] = intval($items[$i]->code); //id
         $response->rows[$i]['cell'] = array($items[$i]->code,
                                                    $items[$i]->name                                            
                                             );
    } 

    echo json_encode($response);    

        jexit();

}
        public function save($tpl = null)
        {
        echo "test";
        jexit();
        }
    }

查看具有类似问题的其他问题,我仔细检查了我的

administrator/components/nutraidev/nutraidev.xml

并确保

<files folder="site">
    <filename>controller.php</filename>

在那里。

我可能会遇到此错误的原因是什么?我也用view.json.php尝试了 并得到了相同的结果。感谢

0 个答案:

没有答案