Welcome Guest, Not a member yet? Register   Sign In
Pagination Problem
#1

[eluser]Andre Dublin[/eluser]
Hello, I'm new to codeigniter and followed a few tuts to help me learn pagination. My problem is that I get a 404 error when I click any of the paginated links???

Here is my controller function

Code:
public function index() {
        $data = array();    
        $config['base_url'] = base_url() . 'index.php/registry/';
        $config['total_rows'] = $this->registry_model->count_records();
        $config['per_page'] = 5;
        $config['num_links'] = 5;
        $config['uri_segment'] = 3;
        $config['full_tag_open'] = '<div id="pagination">';
        $config['full_tag_close'] = '</div>';
        $this->pagination->initialize($config);
        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;

        if ($q = $this->registry_model->get_registry($config['per_page'], $page)) {
            $data['registry'] = $q;
        } else {
            return false;
        }

        $data['title'] = "Events";
        $data['main'] = "registry_view";
        $data['links'] = $this->pagination->create_links();
        $this->load->view('template', $data);
    }

Here is my model function

Code:
//count records
    public function count_records() {
        return $this->db->count_all('Registries');
    }

    //read registry
    public function get_registry($limit, $start) {
        $this->db->limit($limit, $start);
        $q = $this->db->get('Registries');

        if ($q->num_rows() > 0) {
            return $q->result();
        } else {
            return false;
        }

    }

And the view

Code:
<h1>Add Event</h1>
&lt;?php
    echo form_open('registry/create');
    echo form_label('Add Event Name', 'registry_name');
    echo form_input('registry_name', ' ', 'id="add-event"');
    echo form_submit('submit', 'ADD EVENT', 'id="add"');
    echo form_close();
?&gt;
<div class="errors">
    &lt;?php echo validation_errors(); ?&gt;
</div>
<hr />
<table>
    <thead>
        <tr>
            <th>Events</th>
        </tr>
    </thead>
    &lt;?php if (isset($registry)) : foreach ($registry as $row) : ?&gt;
        <tr>
            <td>&lt;?php echo $row->Registry_Name; ?&gt;</td>
            <td>&lt;?php echo anchor('page/index/' . $row->Registry_ID, 'view'); ?&gt;</td>
            <td>
                &lt;?php
                    echo form_open("registry/update/$row->Registry_ID");
                    echo form_label('Update Event Name', 'registry_name');
                    echo form_input('registry_name', ' ', 'class="update-event"');
                    echo form_submit('submit', 'UPDATE', 'class="update"');
                    echo form_close();
                ?&gt;
            </td>
            &lt;?php endforeach; ?&gt;
            &lt;?php else : ?&gt;
            <td>No Events Found</td>
            &lt;?php endif; ?&gt;
        </tr>
</table>
&lt;?php echo $links; ?&gt;

Now I've read some posts here and at stackoverflow and maybe its got to do with my uri->segment, but I've tried different locations in the uri and no luck, also I've read about the routes file might have something to do with this, but I'm lost there.

Please help, and thanks!
#2

[eluser]Andre Dublin[/eluser]
I am also autoloading pagination, database, uri, and my models properly.
#3

[eluser]Mfawa Alfred Onen[/eluser]
Hi,
Did you enable .htaccess re-write to remove index.php? if so, then change
Code:
$config['base_url'] = base_url() . 'index.php/registry/';
to
Code:
$config['base_url'] = base_url() . 'registry/';

Also, I believe that
Code:
$this->uri->segment(3)
will cause problems since
Code:
base_url().index.php
is considered as 1 segment,
Code:
registry
is also considered segment number 2.

Let us know if you have made this changes.

Regards!




Theme © iAndrew 2016 - Forum software by © MyBB