Error with pagination and codeigniter

Asked

Viewed 137 times

2

By clicking on the page link the same returns me a NOT FOUND.

    <div class="scroll">
<table class="table table-hover" id="myTable">
    <thead>
        <tr>
            <th><b>Nome</b></th>
            <th><b>Email</b></th>
            <td><b>Telefone</b></td>
            <td><b>Cidade</b></td>
            <td><b>PR</b></td>
        </tr>
    </thead>

    <tbody>
    <?php foreach ($results as $data) : ?>
        <td><?= $data->nomeCliente ?></td>
        <td><?= $data->emailCliente ?></td>
        <td><?= $data->telefoneCliente ?></td>
        <td><?= $data->cidadeCliente ?></td>
        <td><?= $data->estadoCliente ?></td>            
        <td>
            <a ><i class="glyphicon glyphicon-trash" title="Apagar" onclick="modalDelete()"></i></a>
        </td>

        <td>
            <a href="index.php"><i class="glyphicon glyphicon-edit" title="Editar".></i></a>
        </td>

        <td>
           <a href="index.php"><i class="glyphicon glyphicon-eye-open" title="Visualizar"></i></a>
        </td>
    </tr>
<?php endforeach ?>
</tbody>
</table>
<center>
    <ul class="pagination">
        <li><a><?php echo $links; ?></a></li>
    <ul>
</center>
</div>

Here is the CONTROLLER

public function consultaClientes() {
    $this->output->enable_profiler(TRUE);
    $this->load->model("Cliente/Clientes_Model");
    $config["base_url"] = base_url('index.php/Cliente/');
    $config["total_rows"] = $this->Clientes_Model->record_count();
    $config["per_page"] = 5;
    $config['use_page_numbers'] = TRUE;
    $config["uri_segment"] = 3;
    $choice = $config["total_rows"] / $config["per_page"];
    $config["num_links"] = round($choice);

    $this->pagination->initialize($config);

    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $data["results"] = $this->Clientes_Model
        ->fetch_countries($config["per_page"], $page);
    $data["links"] = $this->pagination->create_links();

    $this->load->view("menu");
    $this->load->view("Cliente/Clientes", $data);
}

Here the MODEL

public function record_count() {
        return $this->db->count_all("cliente");
    }


    public function fetch_countries($limit, $start) {
        $this->db->limit($limit, $start);
        $query = $this->db->get("cliente");

        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
    }

There is still a configured route.

$route['Cliente'] = 'Cliente/Clientes/consultaClientes';

1 answer

0

Seems to me an incorrect routing. When the user type:

www.seu-site.com.br/cliente/

It will be (virtually) taken to:

www.seu-site.com.br/cliente/clientes/consultaClientes

That is, for the method clientes() class Cliente, passing as parameters the string consultaCliente. However, probably there is no method clientes($string) in your class Cliente, also does not make sense the static string 'consultaClientes'.

I think if the intention is to define as the standard class behavior Cliente the visualization of clients, should be excluded the routing and implement the actions within the method called index() class. This is the method that is automatically invoked when something like this is requested:

www.seu-site.com.br/cliente

Browser other questions tagged

You are not signed in. Login or sign up in order to post.