Joomla 2.5 フレームワークを使用しています。
次のような単純なテーブルがあります。
int id
string itemid
ここで、JTable を使用してすべての「itemid」を配列にロードしたいだけです。ここに可能性はありますか?
Joomla 2.5 フレームワークを使用しています。
次のような単純なテーブルがあります。
int id
string itemid
ここで、JTable を使用してすべての「itemid」を配列にロードしたいだけです。ここに可能性はありますか?
JTable クラスに関するすべてが 1 つの行のみを処理します。複数の行が関係する場合、次の 2 つのオプションがあります。
1)あなたが与えた解決策を使用してください。
2) Table クラスで load() 関数をオーバーライドします。これは、次のように実行できます。
次の load() 関数を Table クラスに追加します。
function load($key = null)
{
$db = $this->getDBO();
$query = $db->getQuery(true);
$query->select($key);
$query->from($this->getTableName());
$db->setQuery($query);
$row = $db->loadRowList();
if ($db->getErrorNum())
{
$this->setError($db->getErrorMsg());
return false;
}
// Check that we have a result.
if (empty($row))
{
return false;
}
//Return the array
return $row;
}
ここで、1 つの引数「itemid」を指定して load() 関数を呼び出し、必要な配列を取得します。
これは私にとってはうまくいきました。
私が使用することにした解決策は、JModelList からモデル クラスを継承することです。
class modelModelcomponent extends JModelList
{
protected function getListQuery()
{
// Create a new query object.
$db = JFactory::getDBO();
$query = $db->getQuery(true);
// Select some fields
$query->select('itemid');
// From the hello table
$query->from('#__table');
return $query;
}
}