【问题标题】:Joomla JTable Load Array and edit fieldsJoomla JTable 加载数组和编辑字段
【发布时间】:2014-03-13 13:51:04
【问题描述】:

我看到可以使用带有 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) 是:

Array
(
    [0] => 1
    [1] => 2
)

但我没有运气。我不断收到以下错误:

0 - 数据库中缺少字段:TableDocument 1。

Documentation on JTable

非常感谢任何帮助。

【问题讨论】:

  • 哇,该文档链接不那么出色。 :~(

标签: php arrays joomla joomla3.0


【解决方案1】:

其实你做错了。您可以使用很少的字段值加载 JTable,但它只返回 1 个结果;

使用示例:

$data = array('id' => 100, 'user_id' => 101);
$table->load($data);

上面的代码将搜索 id = 100 AND user_id = 101 的表条目。你不能像那样加载 2 个表条目。

我的建议是:

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;
}

【讨论】:

  • 谢谢你,我明白了,你的建议似乎效果更好,只是它没有更新:date_removed
  • 如果我交换 $return || 似乎工作正常$file->store() 左右。
  • 是的,我的答案可能有误(未在现场测试过),更新了我的答案;
  • @di3sel 让我们帮助您在 JSX 上获得一些积分。请看看这个:joomla.stackexchange.com/q/23156/12352
猜你喜欢
  • 2012-03-24
  • 2012-02-08
  • 1970-01-01
  • 2018-10-12
  • 2012-05-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多