Joomla - Ошибка при сохранении данных в компоненте Joomla

0

Я расширяю один компонент Joomla для Joomla 3. Я могу извлекать данные, но во время хранения данных сталкиваюсь с этой проблемой:

 Table budget not supported. File not found. 

Имя моей таблицы: vaccount_budget.

Моя модель: budget.php

class VaccountModelBudget extends JModelList
{

    function __construct()
    {
        parent::__construct();
        $array = JRequest::getVar('cid',  0, '', 'array');
        $this->setId((int)$array[0]);
    }

    function setId($id)
    {
        // Set id and wipe data
        $this->_id  = $id;
        $this->_data    = null;
    }

    function &getData()
    {
        // Load the data
        if (empty( $this->_data )) {
            $query = ' SELECT * FROM #__vaccount_budget '.
                    '  WHERE id = '.$this->_id;
            $this->_db->setQuery( $query );
            $this->_data = $this->_db->loadObject();
        }
        if (!$this->_data) {
            $this->_data = new stdClass();
            $this->_data->id = null;
            $this->_data->tranid = null;
            $this->_data->quantity = null;
            $this->_data->amount = null;
            $this->_data->from = null;
            $this->_data->to = null;
            $this->_data->created_by = null;

        }
        return $this->_data;
    }

    function store()
    {   
        $row = $this->getTable('budget');
        $data = JRequest::get( 'post' );
        $row->load(JRequest::getInt('id', 0));

        $user = JFactory::getUser();
        $uID = $user->id;
        $data['created_by'] = $uID;
        $data['from'] = "2015-02-18";
        $data['to'] = '2015-02-18';

        if (!$row->bind($data)) {
            $this->setError($row->getError());
            return false;
        }
        // Make sure the transaction record is valid
        if (!$row->check()) {
            $this->setError($row->getError());
            return false;
        }
        // Store the web link table to the database
        if (!$row->store()) {
            $this->setError( $row->getError() );
            return false;
        }
        return true;
    }

Контроллер: budget.php

class VaccountControllerBudget extends JControllerForm
{
    function __construct()
    {
        parent::__construct();
        // Register Extra tasks
        $this->registerTask( 'add'  ,   'edit' );
    }

    function edit($key = NULL, $urlVar = NULL)
    {
        JRequest::setVar( 'view', 'budget' );
        JRequest::setVar( 'layout', 'edit'  );
        JRequest::setVar('hidemainmenu', 1);

        $model = $this->getModel('budget');

        parent::display();
    }

    function save($key = NULL, $urlVar = NULL)
    {
        $model = $this->getModel('budget');
        $task = $this->getTask();
        $link = $task=="apply"?'index.php?option=com_vaccount&view=budget&task=budget.edit&cid[]='.JRequest::getInt('id', 0):'index.php?option=com_vaccount&view=budgets';

        if($task=="save") {
            //$model->checkIn();

            if ($model->store($post)) {
                $msg = JText::_( 'TRANSACTION_SAVED' );
                $this->setRedirect($link, $msg);
            } else {
                $msg = $model->getError();
                jerror::raiseWarning('', $msg);
                $this->setRedirect($link);
            }
        }
    }

Я могу получить данные из базы данных, но не могу хранить данные, когда форма публикует данные. В чем я ошибаюсь?

  • 1
    Вы создали класс JTable в табличном каталоге под администратором?
Теги:
joomla
joomla3.0
joomla-component

1 ответ

1
Лучший ответ

Создать budget.php в: Joomla Root/administrator/components/com_vaccount/tables

jimport('joomla.filter.input');

    class TableBudget extends JTable
    {
        var $id = null;     
        var $created_by = null;
        // Add your field name here

        function TableBudget(& $db) {
            parent::__construct('#__vaccount_budget', 'id', $db);
        }

        function bind($array, $ignore = '')
        {
            if (key_exists('params', $array) && is_array($array['params']))
            {
                $registry = new JRegistry();
                $registry->loadArray($array['params']);
                $array['params'] = $registry->toString();
            }
            return parent :: bind($array, $ignore);
        }

        function check()
        {               

            return parent::check();
        }

        function store($updateNulls = false)
        {
            $user = JFactory::getUser();

            $this->created_by=$user->id;


            if(!parent::store($updateNulls))    {
                return false;
            }
            return true;
        }
    }

Ещё вопросы

Сообщество Overcoder
Наверх
Меню