2015-02-04 3 views
0

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

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 класса в каталоге таблицы под администратором? – jibon57

ответ

1

Создать budget.php в разделе: Joomla Root/администратор/компоненты/com_vaccount/столов

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; 
     } 
    } 
Смежные вопросы