5

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');

この変数はたまたま定義されていません。

私は何が欠けていますか?何らかの形で適切なユーザーセッションに接続されていると思いますが、証拠はまったくありません。

4

2 に答える 2

1

Joomlaは次のようにJModelList定義しますpopulateState

protected function populateState($ordering = null, $direction = null)

クラスにオーバーライドがない場合populateState、これが呼び出されますが、値は取得されません。順序付けを使用する場合、最小要件はデフォルト値を設定することです。順序付けをまったく使用する予定がない場合は、クラスからこのメソッドを完全に削除できます。

したがって、最低限必要なのは、クラスで補間することです

protected function populateState($ordering = null, $direction = null) {
    parent::populateState('id', 'ACS');
}

そうしないと、注文列をクリックしない限り、$state->get()またはに何も表示されません。$this->state->get()次に、親populateStateはリクエストから変数を取得します。

于 2012-11-13T14:56:54.350 に答える