1

次のコードを使用して、検索結果のページネーションを管理しています。

if ($this->input->post('search-notes') && (is_string($this->input->post('search-notes')) || is_string($this->input->post('search-notes')))):
    $this->session->set_flashdata('search-notes', $_POST['search-notes']);
    $post['search-notes'] = $this->input->post('search-notes');
elseif ($this->session->flashdata('search-notes')):
    $this->session->set_flashdata('search-notes', $this->session->flashdata('search-notes'));
    $post['search-notes'] = $this->session->flashdata('search-notes');
endif;
if (isset($post['search-notes']) && is_string($post['search-notes']) && !empty($post['search-notes'])):
...

これらはすべて私の開発用コンピューターでは問題なく動作しますが、実際の Web サイトでは機能しません。最終if()ステートメントは true と評価されません。

ただし、最終ステートメント$post['search-notes']の前または内部で変数をエコーアウトすると、機能します!if()

それはまったく奇妙で、これまでにそのようなものに遭遇したことはありません。

CodeIgniter 2.0 を使用しています

set_flashdata()余談ですが、元のタイトルには「 CodeIgniterの機能に関する問題」というより具体的な内容がありました。しかし、刺激的で過度なモデレーション ルールが原因で、あまり意味のないものに骨抜きにする必要がありました。

4

1 に答える 1

3

最初に出席する必要があるのは$this->session->flashdata('search-notes')、メソッドを呼び出すと'search-notes'、セッションから項目が設定解除されることです。

$this->session->flashdata('search-notes')そのため、2回目に確認すると、'search-notes'存在しなくなります。

アイテムをセッションに保持したい場合は、代わりにset_userdata()andを使用してください。userdata()

また、の最初の呼び出しのkeep_flashdata('search-notes') set_flashdata() またはflashdata()前に使用して、追加の要求を通じて flashdata 変数を保持することもできます。

余談ですが、一緒
に確認する必要はありません。変数が存在しない場合は警告を生成せず、 を返します。isset()!empty()empty() FALSE

CI リファレンス

nettuts+ に関する便利なチュートリアルもあります。


デモとして:
コピーしないで、ロジックを確認してください。

if ($_POST['search-notes'] AND is_string($_POST['search-notes']))
{
    $post['search-notes'] = $this->input->post('search-notes'/*, TRUE*/ /* Enable XSS filtering */);
    $this->session->set_flashdata('search-notes', $post['search-notes']);
}
elseif ($searchNotes = $this->session->flashdata('search-notes'))
{
    $post['search-notes'] = $searchNotes;
}

if (! empty($post['search-notes']) AND is_string($post['search-notes'])):
// ...

search-notesアイテムをセッションに保持する必要がある場合は、最初のifステートメントで次を使用します。

if ($_POST['search-notes'] AND is_string($_POST['search-notes']))
{
    $post['search-notes'] = $this->input->post('search-notes'/*, TRUE*/ /* Enable XSS filtering */);
    $this->session->set_flashdata('search-notes', $post['search-notes']);
    // Keep the flashdata through an additional request
    $this->session->keep_flashdata('search-notes');

} // ...
于 2013-06-29T11:58:37.687 に答える