gpt4 book ai didi

Joomla 组件不保存数据

转载 作者:行者123 更新时间:2023-12-01 11:02:06 25 4
gpt4 key购买 nike

我有一个曾经工作的组件(没有为描述设置 HTML 标签),现在在尝试让 HTML 格式工作后它不会保存。

com_lot\views\lot\tmpl\form.php:

<?php defined('_JEXEC') or die('Restricted access');
$document =& JFactory::getDocument();
$document->addScript('includes/js/joomla.javascript.js');
require_once(JPATH_ADMINISTRATOR .DS. 'components' .DS. 'com_jce' .DS. 'helpers' .DS. 'browser.php');
?>
<form action="index.php" method="post" name="adminForm" id="adminForm">
<script language="javascript" type="text/javascript">
function submitbutton(pressbutton) {
var form = document.adminForm;
if (pressbutton == 'cancel') {
submitform( pressbutton );
return;
}

<?php
$editor =& JFactory::getEditor();
echo $editor->save( 'description' );
?>
submitform(pressbutton);
}
</script>
...
<tr>
<td width="100" align="right" class="key">
<label for="description">
<?php echo JText::_( 'Description' ); ?>:
</label>
</td>
<td>
<?php
$editor =& JFactory::getEditor();
echo $editor->display('description', $this->lotdata->description, '550', '400', '60', '20', false);
?>
</td>
</tr>
...
<input type="hidden" name="option" value="com_lot" />
<input type="hidden" name="lotid" value="<?php echo $this->lotdata->lotid; ?>" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="controller" value="lot" />

<?php echo JHTML::_( 'form.token' ); ?>
<button type="button" onclick="submitbutton('save')"><?php echo JText::_('Save') ?></button>
<button type="button" onclick="submitbutton('cancel')"><?php echo JText::_('Cancel') ?></button>
</form>

com_lot\models\lot.php:

   function store($data)
{
// get the table
$row =& $this->getTable();

// Bind the form fields to the hello table
if (!$row->bind($data)) {
$this->setError($this->_db->getErrorMsg());
return false;
}

// Make sure the hello record is valid
if (!$row->check()) {
$this->setError($this->_db->getErrorMsg());
return false;
}

// Store the web link table to the database
if (!$row->store()) {
$this->setError( $row->getErrorMsg() );
return false;
}

return true;
}

function save()
{
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );

// get the model
$model =& $this->getModel();

//get data from request
$post = JRequest::get('post');
$post['description'] = JRequest::getVar('description', '', 'post', 'string', JREQUEST_ALLOWRAW);

// let the model save it
if ($model->store($post)) {
$message = JText::_('Success');
} else {
$message = JText::_('Error while saving');
$message .= ' ['.$model->getError().'] ';
}
$this->setRedirect('index.php?option=com_lot', $message);
}

感谢任何帮助。

编辑:我看到过关于 JForms 和 XML 文件的资料……这适用吗?我还没有找到任何地方说什么它们的用途,它们有哪些类型......

最佳答案

我发现问题(一旦我稍微清理了代码)是在我关注的文章 (http://docs.joomla.org/How_to_use_the_editor_in_a_component) 中错过了将 store() 更改为 store($data ).

因为页面重定向等它不会死掉并出错。感谢 Jan 的帮助。

关于Joomla 组件不保存数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9794372/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com