Flash数据无法保存

时间:2015-07-08 23:50:50

标签: jquery codeigniter

很抱歉,如果问题重复,但我仍然无法得到正确答案,而且我不想使用userdata,只能使用flashdata。 我的flashdata存在问题。当我设置它时,它没有被设置。请参阅下文并请帮助:

控制器:

public function index() {
    $this->load->model('Lead');
    $leads = $this->Lead->getAllLeads();
    $pageNum = count($leads);
    $this->load->view('main', array('leads' => $leads, 'pageNum' => $pageNum));
}

public function getLeads(){
    $this->load->model('Lead');
    $name = $this->input->post('name');
    $from = $this->input->post('from');
    $to = $this->input->post('to');
    $leads = $this->Lead->getLeads($name, $from, $to);
    $pageNum = count($leads);
    $this->session->set_flashdata('leads', $leads);
    $this->session->set_flashdata('pageNum', $pageNum);
    redirect('main');
}

查看:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
    <script>
    $(document).ready(function(){
        $( ".target" ).change(function(res) {
            var data = $('form').serialize();
            console.log(data);
            $.post('/Leads/getLeads', data, function(res){
                //console.log(res);
            });
        });
    })
    </script>
</head>
<body>
<?php
if ($this->session->flashdata('leads') == TRUE) {
    $leads = $this->session->flashdata('leads');
}
if ($this->session->flashdata('pageNum') == TRUE) {
    $pageNum = $this->session->flashdata('pageNum');
}
?>
    <form method="post" >
        <input class="target" type="text" name="name">
        <input class="target" type="date" name="from">
        <input class="target" type="date" name="to">
        <input class="target" type="hidden" name="pageNumber">
    </form>
    <table class="table table-striped">
        <thead>
            <th>LeadsID</th>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Registered Date/Time</th>
            <th>Email</th>
        </thead>
        <tbody>
        <div id="first">
            <form>
                <?php
                $pagenums = count($leads) / 5 + 1;
                for ($i = 1; $i < $pagenums; $i++){
                    ?>
                        <a href="/Books/getPart/<?= $i ?>"><?= $i; ?></a> |
                    <?php
                }
                ?>
            </form>
        </div>
        <?php
        foreach ($leads as $lead) {
            ?>
            <tr>
                <td><?= $lead['id']; ?></td>
                <td><?= $lead['first_name']; ?></td>
                <td><?= $lead['last_name']; ?></td>
                <td><?= $lead['registered_datetime']; ?></td>
                <td><?= $lead['email']; ?></td>
            <?php
        }
        $this->session->sess_destroy();
        ?>
        </tbody>
    </table>
</body>

如您所见,我在Controller中设置了flashdata并尝试从View访问它。当我打印它时,它显示我booleanFALSE。 非常感谢!

P.S。:做了一些改变,所以我现在在这里。再说一次,首先,当我发布时,我没有flashdata,只是直接打开&#39; main&#39;使用$ this-&gt; load-&gt;查看...其次,再次使用新的&#39; $ lead&#39;和&#39; $ pageNum&#39;数据。这就是我想要的一切。当请求的数据在表单中更改时进行更改。

0 个答案:

没有答案