Welcome Guest, Not a member yet? Register   Sign In
using the paginating class
#1

[eluser]DumpProgrammer[/eluser]
I need to use the paginating class but I am to sure on how I can implement it in my view file. My home page is like this
Code:
<?php $this->load->view('newheader'); ?>
<?php $this->load->view('newnav'); ?>
&lt;!-- end #sidebar1 --&gt;</div>
<div id="mainContent">

&lt;?php $this->load->view('newfeatured');?&gt;
&lt;?php $this->load->view('newcontent');?&gt;
&lt;?php $this->load->view('footer'); ?&gt;
I need to put the pagination in the newcontent.php so will I be able to load the paginating class in the view file because in the controller I am only loading the info that will be required by all these views.

I would also like to add a div tag for every 2 items and display 4 per page so is there somewhere in the config file I can add the div for every 2 items.
#2

[eluser]codeshadow[/eluser]
Hi,

You can load the library and generate the links in your controller itself. The controller would pass the necessary data to your view file. Basically, if you are getting records from your database, for example, and wish to display it using pagination, the controller would fetch all the data from the database and would run a query with a limit parameter to it. Your view simply would print your data in the desired format.

Quote:I would also like to add a div tag for every 2 items and display 4 per page so is there somewhere in the config file I can add the div for every 2 items.

You can do that in the view.

Refer to the user guide to see how to use the pagination class.

Happy coding :coolsmile:
#3

[eluser]DumpProgrammer[/eluser]
Sorry but I cant understand how I will be able to implement that because I think my problem has been started by how I have done my site all together. I am loading multiple views but only calling them from the view file. I will have to try to move all my views to load from the controller and not directly in the view. After that I can the use the paginating class from the controller.

I will have to see how I can easily concat the views into the controller. I have solved the inserting of div tags after every 2 items by using
Code:
if($z%2) and $z++
but I am still stuck on the paginating. Until I can get all this
Code:
&lt;?php $this->load->view('newheader'); ?&gt;
&lt;?php $this->load->view('newnav'); ?&gt;

&lt;?php $this->load->view('newfeatured');?&gt;
&lt;?php $this->load->view('newcontent');?&gt;
&lt;?php $this->load->view('footer'); ?&gt;
into the controller then I will be sorted.
#4

[eluser]DumpProgrammer[/eluser]
I have put everything in the controller but I cannot the paginating to work here is how my controller is looking like
Code:
function index()
    {
    $data['posts'] = array(); //we will replace soon!
    $data['cats'] = $this->MCats->getTopCategories(); //we will replace soon!
    $data['title'] = "Shout-Africa";
    $data['main'] = 'public_home';
    $data['featured'] = $this->MPosts->getAllFeaturedPosts();
    $data['post'] = $this->MPosts->getAllActivePosts();
    $this->load->vars($data);
    $this->load->view('newheader');
    $this->load->view('newnav');
    $this->load->view('newfeatured');
    
    // set pagination parameters
    $this->load->library('pagination');
    $config['base_url']=base_url();
    $config['total_rows'] = $this->db->count_all('posts');
    $config['per_page'] = '4';
    $config['full_tag_open']='<div class="box">';
    $config['full_tag_close']='</div>';
    $this->pagination->initialize($config);
    // create pagination links
    $data['links']=$this->pagination->create_links();
    // load 'blogger_view' view
    $this->load->view('newcontent',$data);
    $this->load->view('footer');

    }




Theme © iAndrew 2016 - Forum software by © MyBB