我看到可以使用Jtable加载数组,我尝试了以下操作:
public function delete($id = null) {
$app = JFactory::getApplication();
$id = $id ? $id : $app->input->get('files', array(), 'ARRAY');
$file = JTable::getInstance('Document','Table');
$file->load($id);
$file->date_removed = date("Y-m-d H:i:s",time());
if($file->store())
{
return true;
} else {
return false;
}
}
print_r($id)
is:
Array
(
[0] => 1
[1] => 2
)
但是我运气不好。我一直得到以下错误:
0 -数据库中缺少字段:TableDocument 1 .
JTable文档
其实你做错了。您可以加载带有几个字段值的JTable,但它只返回一个结果;
使用例子:
$data = array('id' => 100, 'user_id' => 101);
$table->load($data);
上面的代码将搜索id = 100且user_id = 101的表项。你不能像这样加载两个表项。
我的建议是:public function delete($id = null) {
$ids = array();
$return = true;
if ($id) {
$ids[] = $id;
} else {
$ids = JFactory::getApplication()->input->get('files', array(), 'ARRAY');
}
if (count($ids) > 0) {
foreach ($ids as $id) {
$file = JTable::getInstance('Document','Table');
$file->load($id);
$file->date_removed = date("Y-m-d H:i:s",time());
$temp = $file->store();
$return = $return || $temp;
}
}
return $return;
}