Joomla バックエンドでテーブルの列を並べ替えています。このチュートリアルに従って設定を調整します。
ご覧のとおりpopulateState
、メソッドをオーバーライドして、並べ替えオプションを手動で取得することをお勧めします。
public function populateState() {
$filter_order = JRequest::getCmd('filter_order');
$filter_order_Dir = JRequest::getCmd('filter_order_Dir');
$this->setState('filter_order', $filter_order);
$this->setState('filter_order_Dir', $filter_order_Dir);
}
com_content
しかし、ネイティブ コンポーネントがこれらのオプションをモデル ファイルで明示的に設定していないことに気付きましたadministrator/components/com_content/models/articles.php
。
protected function populateState($ordering = null, $direction = null)
{
// Initialise variables.
$app = JFactory::getApplication();
$session = JFactory::getSession();
............................................
............................................
............................................
// List state information.
parent::populateState('a.title', 'asc');
}
代わりに、parent を呼び出すだけpopulateState
です。そして実際JModelList::populateState()
にはこれが含まれます:
protected function populateState($ordering = null, $direction = null)
{
// If the context is set, assume that stateful lists are used.
if ($this->context) {
$app = JFactory::getApplication();
.....................................
.....................................
.....................................
$value = $app->getUserStateFromRequest($this->context.'.ordercol', 'filter_order', $ordering);
if (!in_array($value, $this->filter_fields)) {
$value = $ordering;
$app->setUserState($this->context.'.ordercol', $value);
}
$this->setState('list.ordering', $value);
// Check if the ordering direction is valid, otherwise use the incoming value.
$value = $app->getUserStateFromRequest($this->context.'.orderdirn', 'filter_order_Dir', $direction);
if (!in_array(strtoupper($value), array('ASC', 'DESC', ''))) {
$value = $direction;
$app->setUserState($this->context.'.orderdirn', $value);
}
$this->setState('list.direction', $value);
}
else {
$this->setState('list.start', 0);
$this->state->set('list.limit', 0);
}
}
そこで、ネイティブのコードを真似ようとしていますcom_content
。したがって、私はそれを仮定します
class CompViewData extends JView
{
function display($tpl = null)
{
$this->state = $this->get('State');
親を呼び出しJModelList::populateState()
て (モーダル クラスでオーバーライドしていないので)、 set を設定し$this->setState('list.ordering', $value);
ます。しかし、何らかの理由で、注文を使用して SQL クエリを作成するために呼び出す$this->state->get()
と、getListQuery()
protected function getListQuery()
{
$orderCol = $this->state->get('list.ordering', 'id');
$orderDirn = $this->state->get('list.direction', 'asc');
この変数はたまたま定義されていません。
私は何が欠けていますか?何らかの形で適切なユーザーセッションに接続されていると思いますが、証拠はまったくありません。