Joomla - 在 Joomla 组件中存储数据时出错
Posted
技术标签:
【中文标题】Joomla - 在 Joomla 组件中存储数据时出错【英文标题】:Joomla - Error during store data in Joomla component 【发布时间】:2015-04-04 09:12:03 【问题描述】:我正在为 Joomla 3 扩展一个 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);
我可以从数据库中获取数据,但在表单发布数据时无法存储数据。我在哪里做错了?
【问题讨论】:
你在admin下的table目录下创建JTable类了吗? 【参考方案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;
【讨论】:
以上是关于Joomla - 在 Joomla 组件中存储数据时出错的主要内容,如果未能解决你的问题,请参考以下文章
在 joomla 组件中,我应该在哪里存储数据库函数,以及如何调用它们?