简体   繁体   English

Joomla 2.5 MVC Model prepareTable函数

[英]Joomla 2.5 MVC Model prepareTable function

while developing a MVC Component, I'm faced with the following problem: Before saving the posted data from the default.php, some data should be revised, if necessary. 在开发MVC组件时,我遇到了以下问题:在保存default.php中发布的数据之前,如有必要,应修改一些数据。 From what I know so far, the protected Function prepareTable(&$table) in the specific Model should cover my need. 据我所知,到目前为止,特定模型中受保护的Function prepareTable(&$ table)应该满足我的需求。 I started with a very simple approach, as follows: 我从一个非常简单的方法开始,如下所示:

protected function prepareTable(&$table){

$table=$this->getTable();

$table->image="HelloWorld";

}

My expectation is, that after submitting the template a specific field in my table has now the value "HelloWorld", but it isn't. 我的期望是,在提交模板后,我的表中的特定字段现在具有值“HelloWorld”,但事实并非如此。

Perhaps, someone could give me an advice how to handle the prepareTable() function? 也许,有人可以给我一个如何处理prepareTable()函数的建议?

Thank you 谢谢

If everything else is setup correctly the prepareTable(&$table) method already has the table object passed into it. 如果其他所有设置都正确,则prepareTable(&$table)方法已经将表对象传递给它。

Generally a prepareTable() in your class wouldn't getTable() , as you replace the $table being passed in which already has the row data bound to it. 通常,类中的prepareTable()不会是getTable() ,因为您替换了传入的$table ,该$table已经绑定了行数据。 By replacing it you effectively decouple from the work already done. 通过更换它,您可以有效地与已经完成的工作分离。

I would remove that line your method looks like: 我会删除你的方法看起来像这样的行:

protected function prepareTable(&$table){

    $table->image="HelloWorld";

}

If you look at the simplest implementation of prepareTable() in the Joomla core files, in com_banners you will see something very similar to your method; 如果你看一下Joomla核心文件中最简单的prepareTable()实现,在com_banners你会看到与你的方法非常相似的东西;

/**
 * Prepare and sanitise the table data prior to saving.
 *
 * @param   JTable  A JTable object.
 * @since   1.6
 */
protected function prepareTable(&$table)
{
    $table->name = htmlspecialchars_decode($table->name, ENT_QUOTES);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM