CodeIgniter Forums
Paginating Search Results - 404 Error - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Paginating Search Results - 404 Error (/showthread.php?tid=19578)

Pages: 1 2 3


Paginating Search Results - 404 Error - El Forum - 06-11-2009

[eluser]mpar612[/eluser]
Hello, I am trying to implement pagination for the the first time. The code below works fine except for the pagination. The view page displays the appropriate number of search results and the page number links appear in the right place, but when I click on any of the page numbers I get " 404 Page Not Found The page you requested was not found."

I have searched through the forums and am leaning towards this being a URI problem, but I have not found a resolution.

Any assistance would be greatly appreciated. Thanks in advance!


Controller:

Code:
class Basicidx extends Controller {
    
function index() {

    $this->load->helper(array('form', 'url'));
    $this->load->library('form_validation');
    $this->load->database();
        
    $this->form_validation->set_rules('city', 'City', 'trim|required|min_length[5]|max_length[12]|xss_clean');
    $this->form_validation->set_rules('minPrice', 'Minimum Price', 'trim|integer|xss_clean');
                
    if ($this->form_validation->run() == FALSE)
    {
        $this->load->view('myform');
    }
    else
    {
            
        $this->load->library('pagination');
            
        $config['base_url'] = site_url('basicidx');
        $config['total_rows'] = $this->db->count_all_results('residential');
        $config['per_page'] = '5';
        $config['uri_segment'] = 2;

        $this->pagination->initialize($config);
            
        //load the model and get results
        $this->load->model('basicidx_model');
        $data['query'] = $this->basicidx_model->getIdx($config['per_page'],$this->uri->segment(2));
            
        $this->load->view('formsuccess', $data);
    }
}
}

Model:

Code:
class basicidx_model extends Model{

function Basicidx(){

// call the Model constructor
parent::Model();

// load database class and connect to MySQL
$this->load->database();
}

function getIdx($num, $offset){

    $city = $this->input->post('city');
    $minPrice = $this->input->post('minimum');
    
    $this->db->where('City', $city);
        
    if(isset($minPrice)){
        $this->db->where('ListPrice >=', $minPrice);
    }
    
    $query = $this->db->get('residential', $num, $offset);
    return $query;

}
}

View:
Code:
<html>
<head>
<title>My Form</title>
</head>
<body>

<h3>Your form was successfully submitted!</h3>

&lt;?php foreach($query->result() as $row): ?&gt;

<h3>&lt;?=$row->MLSNumber?&gt;</h3>
<p>&lt;?=$row->City?&gt;</p>
<p>&lt;?=$row->No_Bedrooms?&gt;</p>
<p>&lt;?=$row->ListPrice?&gt;</p>

<hr>

&lt;?php endforeach; ?&gt;

<p>&lt;?php echo anchor('basicidx', 'Try it again!'); ?&gt;</p>
<p>&lt;?php echo $this->pagination->create_links(); ?&gt;</p>
&lt;/body&gt;
&lt;/html&gt;



Paginating Search Results - 404 Error - El Forum - 06-11-2009

[eluser]richwalkup[/eluser]
If you are getting 404 errors, it's related to how you have configured your CI setup. Either you do not have the proper .htaccess file in the public web root, it's improperly configured, or your web host doesn't support URL rewrites (uncommon and unlikely).

Something unrelated that you want to look into is the constructor of your model class. It should be:

Code:
function basicidx_model(){
    // call the Model constructor
    parent::Model();

   // load database class and connect to MySQL
   // $this->load->database(); /* this line is not necessary in the model definition and should be in the controller (which you already have) */
}

The way you currently have your constructor written, it is never firing and is not initializing the constructor of the base Model class and therefore not really working properly.

Secondary to that, standard convention would have you name your model class Basicidx rather than basicidx_model, but as with most things in CI, it's just a suggestion, not a requirement.


Paginating Search Results - 404 Error - El Forum - 06-11-2009

[eluser]mpar612[/eluser]
Thanks for the tips!

Is this the .htaccess file that I need to create in my websites root directory: http://codeigniter.com/wiki/mod_rewrite/? It belongs in the root directory of my website not within the system directory, right?

Thanks again!


Paginating Search Results - 404 Error - El Forum - 06-12-2009

[eluser]richwalkup[/eluser]
[quote author="mpar612" date="1244785096"]
Is this the .htaccess file that I need to create in my websites root directory: http://codeigniter.com/wiki/mod_rewrite/? It belongs in the root directory of my website not within the system directory, right?
[/quote]

Yes, that is the .htaccess file you would want to use and it does belong in the public document root.


Paginating Search Results - 404 Error - El Forum - 06-12-2009

[eluser]mpar612[/eluser]
Thanks! I added the .htaccess file and enabled mod_rewrite in my httpd.conf file and I am still getting 404 errors with pagination.

Does anyone have any thoughts?

Thanks!


Paginating Search Results - 404 Error - El Forum - 06-12-2009

[eluser]TheFuzzy0ne[/eluser]
Are your file names in lowercase?


Paginating Search Results - 404 Error - El Forum - 06-12-2009

[eluser]mpar612[/eluser]
Yes, they are all lower case.


Paginating Search Results - 404 Error - El Forum - 06-12-2009

[eluser]TheFuzzy0ne[/eluser]
Try changing the uri_protocol in your config.php. see if that helps. One of those options should work.


Paginating Search Results - 404 Error - El Forum - 06-12-2009

[eluser]mpar612[/eluser]
I tried each of the uri_protocol options and I still got 404 errors.

Here is how I access my search from:
http://www.domain.com/basicidx

The search results are produced on:
http://www.domain.com/basicidx

The pagination links try to access this page:
http://www.domain.com/basicidx/5

Does this seem right? Should the initial search results page include something like basicidx/#?

Thanks in advance!


Paginating Search Results - 404 Error - El Forum - 06-12-2009

[eluser]TheFuzzy0ne[/eluser]
Does http://www.domain.com/basicidx work directly? If not, does it work like this: http://www.domain.com/index.php/basicidx