Codeigniter表单验证和分页问题

时间:2014-06-02 19:43:34

标签: php codeigniter pagination

我正在尝试我的第一个codeigniter分页程序。我在网站上有一个我正在处理的例程,让您从输入表单中提供的输入值查看记录。换句话说,我想为居住在纽约的人选择所有记录,然后从下拉列表中选择纽约。从那里,控制器功能对值进行验证,如果它很好,你应该看到来自纽约的所有记录。但是,我只看到reords的第一页基于我指定的每页记录的数量。当我尝试转到下一页时,它会将我带回输入表单。以下是代码:

   public function view() {   
         $this->form_validation->set_rules('state', 'state', 'trim|required');

         if($this->form_validation->run() == FALSE) {
            $this->load->view('view');
         } else {
            $state = $this->input->post('state');

            // **** HERE IS WHERE THE PAGINATION ROUTINE STARTS ****

            // Setup the SELECT statement
            $qry = "SELECT city, state, person_name, person_gender, photo_url";
            $qry = $qry . " FROM membership m JOIN people p ON m.email_address = p.email_address";
            $qry = $qry . " WHERE state = '".$state."' ORDER BY state ASC, person_name ASC";

            // Set the limit and offset
            $limit = 2;
            $offset = ($this->uri->segment(3) != '' ? $this->uri->segment(3) : 0);

            // Setup the $config variables for pagination
            $config['base_url'] = 'http://www.somewebsite.com/ci/index.php/cr/view';
            $config['total_rows'] = $this->db->query($qry)->num_rows();
            $config['uri_segment'] = 3;
            $config['per_page'] = $limit;
            $config['num_links'] = 10;
            $config['full_tag_open'] = '<div id="pagination">';
            $config['full_tag_close'] = '</div>';

            // Initialize the $config
            $this->pagination->initialize($config);

            // Limit and get the data
            $qry = $qry . " LIMIT {$limit} OFFSET {$offset}";
            $data['result_per_page'] = $this->db->query($qry)->result();

            // Now go and display the data
            $this->load->view('people', $data);

            // **** HERE IS WHERE THE PAGINATION ROUTINE STOPS ****

         }
   }

现在请注意,如果我自己编写了分页例程,而没有经过验证并对值进行了硬编码&nbsp;&#39; NY&#39;分页程序完美无缺。但是,它会继续重新加载输入表单以选择状态。我对Codeigniter和PHP相对较新,但有一种方法可以绕过以下代码:

if($this->form_validation->run() == FALSE) {
        $this->load->view('view');
     } else {
        $state = $this->input->post('state');

初次运行后的功能?我感谢你对此事的任何帮助。谢谢。

0 个答案:

没有答案