Search code examples
phpjoomlajoomla3.0joomla-component

Joomla - Error during store data in Joomla component


I am extending one Joomla component for Joomla 3. I can retrieve data but during storing data I am facing this problem:

 Table budget not supported. File not found. 

My table name: vaccount_budget .

My model: 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;
    }

Controller: 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);
            }
        }
    }

I can get data from database but can't store data when form post the data. In where I am doing wrong?


Solution

  • Create budget.php under : 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;
            }
        }