Welcome Guest, Not a member yet? Register   Sign In
error in pagination anyone can help me
#1

[eluser]maddy_ssn[/eluser]
hi 2 everyone i am creating a blog
this is my code . In this code iam trying to implement the pagination in my blog ,this is
controller part
<?php
class Blog extends Controller {

function Blog()
{
parent::controller();
$this->load->helper('url');
$this->load->helper('form');
$this->load->database();

}

function index()
{
$s['title'] = "Learning CodeIgniter";
$s['heading'] = "Learn The Basics of CodeIgniter";
$s['query'] = $this->db->get('entries');
$this->load->view('blogs_view',$s);
$this->load->library('pagination');
$config['base_url'] = base_url().'index.php/blog/comments/';
$config['total_rows'] = $this->db->count_all('entries');
$config['per_page'] = 04;
$config['full_tag_open'] = '<p>';
$config['full_tag_close'] = '</p>';
$this->pagination->initialize($config);
$this->load->model('blog_model');
$data['results'] = $this->blog_model->get_blog($config['per_page'],$this->uri->segment(3));
$this->load->view('blogs_view',$data);
}
function comments()
{
$s['title'] = "Learning comments CodeIgniter";
$s['heading'] = "Leraning The Basics";
$this->db->where('entry_id',$this->uri->segment(3));
$s['query'] = $this->db->get('comments');
$this->load->view('comment_view',$s);
}
function comment_insert()
{
$this->db->insert('comments', $_POST);
redirect('blog/comments/'.$_POST['entry_id']);
}

}
?&gt;

and this my model part

&lt;?php
class blog_model extends Model {
function blog()
{
parent::Model();
}
function get_blog($num, $offset)
{
$query = $this->db->get('comments', $num, $offset);
return $query;
}
}
?&gt;
problem is, when i run the code it will show the following error

An Error Was Encountered

Unable to locate the model you have specified: blog_model

but i saved my model file in model folder.so anyone help me to finish my blog
#2

[eluser]Gabriel P[/eluser]
Hy maddy_ssn,

Try this without a model:

In controller:
Code:
function test()
    {
        
        $this->db->orderby("what", 'write sort');
        $query = $this->db->query("SELECT COUNT(*) AS count FROM table");
        $row = $query->row();
        $total_rows = $row->count;

        // Run the limited version of the query
        $per_page = 5;
        $this->db->use_table('table');
        $this->db->limit($per_page);
        
        if ($this->uri->segment(3) !== FALSE)
        {
            $this->db->offset($this->uri->segment(3));
        }          
        $data['query'] = $this->db->get();

        $config['base_url'] = 'http://your-base-url';//Where this controller is! Ex: http://localhost/test-script/index.php/controller-name/test
        $config['total_rows'] = $total_rows;
        $config['per_page'] = $per_page;

        $this->pagination->initialize($config);
        $data['paging'] = $this->pagination->create_links();
        
        
        $this->load->view('view_file', $data);
    }

In the view file:
Code:
&lt;?php foreach ($query->result() as $q): ?&gt;
    //output something here like $q->something_from_db
&lt;?php endforeach; ?&gt;

&lt;?php
echo $paging;
?&gt;

That`s it.
Gabriel

EDIT: Don`t forget to call the paging. I call it in construct function
Code:
$this->load->library('pagination');
#3

[eluser]ztinger[/eluser]
Well, the error is not in pagination, not yet at least, you have first to name correctly your model.

Code:
&lt;?php
class blog_model extends Model {
function blog()
{
parent::Model();
}
function get_blog($num, $offset)
{
$query = $this->db->get('comments', $num, $offset);
return $query;
}
}
?&gt;

ok

take into account that the name of the class must be capitalized, and also the name of the constructor must be the same of the name of the class (this is php 101).

btw: there is no need to call your models with the 'model' suffix.

so I would suggest naming your model simply Blog
and then, within it , start with the following:

and this my model part

Code:
&lt;?php
class Blog extends Model {
function Blog()
{
parent::Model();
}
function get_blog($num, $offset)
{
//...
your function here
?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB