5

ページネーションはgetUserStateFromRequestメソッドを使用してlimitandlimitstart変数を取得しているため、あるコンポーネントから別のコンポーネントに移動すると、アイテムが見つからないというメッセージが表示されるという問題があります。

明確にするために、3ページ分の製品がリストされている製品コンポーネントがあります。次に、2 ページ分のブランチ情報を含むブランチ コンポーネントがあります。そのため、製品リストの 3 ページ目に移動してからブランチ コンポーネントに移動すると、何も表示されません。

これが起こらないようにする方法を知っている人はいますか? セッションデータをクリアする方法はありますか?

4

3 に答える 3

1

私がやったのはこれで、libraries/joomla/application/application.phpファイルの624行目に次の行を追加しました

$this->setUserState('option','default');

        $curr_comp = JRequest::getCmd( 'option' );;


        if($this->getUserState('option') != $curr_comp)
        {
            $this->setUserState($option . 'limitstart',0);
            $this->setUserState('option',$curr_comp);

        }

関数全体がこれを読み取り、

public function getUserStateFromRequest($key, $request, $default = null, $type = 'none')
    {

        $this->setUserState('option','default');

        $curr_comp = JRequest::getCmd( 'option' );


        if($this->getUserState('option') != $curr_comp)
        {
            $this->setUserState($option . 'limitstart',0);
            $this->setUserState('option',$curr_comp);

        }
        $cur_state = $this->getUserState($key, $default);
        $new_state = JRequest::getVar($request, null, 'default', $type);


        // Save the new value only if it was set in this request.
        if ($new_state !== null)
        {
            $this->setUserState($key, $new_state);
        }
        else
        {
            $new_state = $cur_state;
        }

        return $new_state;
    }

これは今のところ問題なく動作しているようです。ただし、実際のサイトに実装する前にテストしてください

于 2012-10-08T11:45:05.560 に答える
1

コア ファイルを編集しないようにしますが、その効果は拡張機能に限定されます (そのため、他の拡張機能は間違ったページに読み込まれる可能性がありますが、あなたのページには読み込まれません)。また、モデルがモデル リストを拡張する場合は、getStart()メソッドをオーバーライドします。

public function getStart()
{
    $store = $this->getStoreId('getstart');
    $input = JFactory::getApplication()->input;
    $start = $limitstart = $input->getInt('limitstart', 0);
    $this->setState('list.start', $limitstart); // maybe redundant

    $limit = $this->getState('list.limit');
    $total = $this->getTotal();
    if ($start > $total - $limit)
    {
        $start = max(0, (int) (ceil($total / $limit) - 1) * $limit);
    }

    // Add the total to the internal cache.
    $this->cache[$store] = $start;
    return $this->cache[$store];
}    

システム全体およびすべての拡張機能で機能するソリューションが必要な場合は、プラグインの実装で modellist をオーバーライドできる必要があります。ここから始めてください。

于 2013-12-31T01:09:39.413 に答える