Joomla组件更新数据

时间:2014-06-29 14:38:21

标签: php joomla components joomla3.0 joomla-extensions

我正在使用Joomla 3组件。目前我正在为后端编程。我有一个表单来添加新数据,它运行得很好。但是当我想更新数据时,组件会创建一个新项而不是更新现有项。 我正在寻找让Joomla知道的位置,这是一个更新,但没有成功。

所以我的问题是:Joomla更新数据的信息是什么?

我的代码: 表:的 ia.php

class mkTableia extends JTable
{
        /**
         * Constructor
         *
         * @param object Database connector object
         */
        function __construct(&$db) 
        {
                parent::__construct('#__tbl_ia', 'ID', $db);
        }
}

型号:ia.php

class mkModelia extends JModelAdmin
{

        public function getTable($type = 'ia', $prefix = 'mkTable', $config = array()) 
        {
                return JTable::getInstance($type, $prefix, $config);
        }

        public function getForm($data = array(), $loadData = true) 
        {
                // Get the form.
                $form = $this->loadForm('com_mk.ia', 'ia',
                                        array('control' => 'jform', 'load_data' => $loadData));
                if (empty($form)) 
                {
                        return false;
                }
                return $form;
        }

        protected function loadFormData() 
        {
                // Check the session for previously entered form data.
                $data = JFactory::getApplication()->getUserState('com_mk.edit.ia.data', array());
                if (empty($data)) 
                {
                        $data = $this->getItem();
                }
                return $data;
        }
}

查看:view.html.php

class mkViewia extends JViewLegacy
{
        /**
         * display method of Hello view
         * @return void
         */
        public function display($tpl = null) 
        {
                // get the Data
                $form = $this->get('Form');
                $item = $this->get('Item');

                // Check for errors.
                if (count($errors = $this->get('Errors'))) 
                {
                        JError::raiseError(500, implode('<br />', $errors));
                        return false;
                }
                // Assign the Data
                $this->form = $form;
                $this->item = $item;

                // Set the toolbar
                $this->addToolBar();

                // Display the template
                parent::display($tpl);
        }

        /**
         * Setting the toolbar
         */
        protected function addToolBar() 
        {
                $input = JFactory::getApplication()->input;
                $input->set('hidemainmenu', true);
                $isNew = ($this->item->ID == 0);

                JToolBarHelper::title($isNew ? JText::_('COM_MK_MANAGER_MK_NEW')
                                             : JText::_('COM_MK_MANAGER_MK_EDIT'));
                JToolBarHelper::save('IA.save');
                JToolBarHelper::cancel('IA.cancel', $isNew ? 'JTOOLBAR_CANCEL'
                                                                   : 'JTOOLBAR_CLOSE');
        }
}

0 个答案:

没有答案