Try Tuts+ Premium, Get Cash Back!
CodeIgniter from Scratch Day 7: Pagination
videos

CodeIgniter from Scratch Day 7: Pagination

This entry is part 7 of 17 in the CodeIgniter From Scratch Session
« PreviousNext »

In these last two weeks, I’ve received bunches of requests for a CodeIgniter pagination screencast; so that’s what we’ll be reviewing today! As a bonus, we’ll also take a look at the super convenient HTML Table class.

Catch Up

Day 7: Pagination

Other Viewing Options

Pagination

Thank you, Screencast.com!


Screencast.com

…for providing the hosting for these video tutorials.


Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • Vitesse

    Yeah!!

    Thank you Jeff :D

    Been waiting for this!

    • http://www.massbase.com/enatom enatom

      ENOUGH CODE-IGNITER TUTS…… plz.

      • Brian

        Vitesse! If You don’t appreciate Jeffrey Way screencast for Codeigniter then maybe you should check other marketplaces.

    • http://www.zarpio.co.nr Khalil

      Yes, this is good… Thanks

      • Fynn

        Indeed, I’ve been really enjoying all the CI tuts! Thanks Jeff. (Although I’ve figured out CI pagination after I’ve watched the first few tuts of CI here)

        Ps.. I would really like to see a CI ACL tut :)

  • myname

    2nd

  • http://butenas.com Ignas

    really nice… run it through and liked. I’ll look this deeply later, but thanks!

  • http://gravityfx.org/ emcgfx

    Thank you Jeff, ones again for posting my request. Very good video. I also like that you include the offline download version of the video. Thank you so much.

    • http://www.jeffrey-way.com Jeffrey Way
      Author

      Yep. I’m also upload iTunes and FLV versions right now. I’ll update the article when they’re ready.

      • zaiful

        Hey Jeffrey, any chance to upload CI day 5 and day 6 videos to blip.tv, please. I still couldn’t download them from screencast.com :( really missing the sequence

      • http://www.jeffrey-way.com Jeffrey Way
        Author

        Okay – added download link, iTunes version, and FLV (Blip) version.

      • zaiful

        Couldn’t find the flv version download links for Day 5 and Day 6 on blip.tv :(

        Anyway, thanks for giving reply at least!!

  • http://ffffffive.com Henry

    Thanks for this Jeff! I keep wondering why you aren’t using Windows any more…

    • http://www.jeffrey-way.com Jeffrey Way
      Author

      I used to use Windows because that’s what Camtasia Studio was made for (recording software). But honestly, I think that a Mac is better suited for me.

  • http://www.complimedia.com Montana Flynn

    I love these CodeIgnitor tutorials! I would love to see some plus tuts on building simple CMS’s and such…

    • scherii

      Ya, me too – this would be great. In this case I would get a plus account :)

  • C.44

    Ah :) more CI love from Jeffrey :) should keep me occupied for a little while again.

    Btw, do you think you could do something AJaX related in the next one ? Hopefully we’ll see the other screencasts prior to this one on iTunes aswell ?

  • http://www.fatlizardmedia.com Juan C Rois

    Jeff, thanks for this tutorial, it’s super useful, I’m going to implement this for one of my projects.
    I have a question about the previous tutorial (Code Igniter Day 6), related to the session and cookies. Can I post it here or is there better way to ask you. It’s keeping me up at night and I have not been able to find an answer elsewhere.

    Thank you very much for all the quality material that you provide for the community.

    • yellow_leopard

      I’d love to see Mr. Way release a follow up CI tut on some advanced cookie and session stuff to better secure applications – maybe even include a bonus like working with the new cart class and ecommerce.

  • http://www.philohermans.com Philo

    Nice Tutorial Jeffrey! :)

  • Jerichvc

    Hi Jeff, maybe in future session you would consider ajax to ci like jquery lib to it. I think it will show the quickness of CI since day 1 of ci series. i’ll wait for it.
    thanks.

  • http://www.hdesignsplus.com Hooman Asgari

    Finally out, took so long but definitely worth the wait, Thanks Jeff

  • Dirk Franssen

    Way to go Jeff! I’m really enjoying those screencasts! Thx

  • http://gravityfx.org/ emcgfx

    Hey Jeff, can you also please upload mp4′s for the following videos you did previous. I would like to re-watch them offline on my laptop. I hope I’m not asking to much. Thank you buddy.

    Day 1: Getting Started With the Framework
    Day 2: Database Selecting Methods
    Day 3: Sending Emails
    Day 4: Newsletter Signup

    • http://www.jeffrey-way.com Jeffrey Way
      Author

      Okay – I’ll try to get those up this week.

      • arnold

        wow! thanks jeff

      • http://gravityfx.org/ emcgfx

        Thank you Jeff ;-) I’ve watched your pagination video yesterday, and followed it up. You did everything almost exactly what I did just couple days before this video :-) Of course it took me a while to figure it out. But what I did is to write special function for pages() and just re-used it in all of my pages :-) It works great.

    • http://www.fatlizardmedia.com Juan C Rois

      I got the first 5 from Itunes

  • http://gravityfx.org/ emcgfx

    I’ve just thought of another idea for your screen casts ;-) You can add some kind of low-level music in the background. Will make your videos more fun LOL

  • http://gravityfx.org/ emcgfx

    Here is data tables for this video, if any one interested ;-)
    http://gravityfx.org/pub/ci/ci_day7.sql

  • Bretticus

    I do primarily server-side coding. I don’t get my hands on too much design. I always laugh when Jeff says something along the lines, “Gotta do some CSS. Skip ahead if this bores you…” I think those are by far the most fascinating parts!

    • http://www.jeffrey-way.com Jeffrey Way
      Author

      Haha. I just say that when the focus leaves CI for a few minutes. I agree with you. :)

      • http://gravityfx.org/ emcgfx

        I love the css part of the tutorials and never skip them ;-) I think you should really do some CSS videos in the future, like maybe CodeIgniter web 2.0 style template with XHTML Strict, CSS, maybe even some Ajax.

  • http://www.milesj.me/ Miles Johnson

    Since you are doing CI tutorials, I could submit many CakePHP tutorials, maybe. Haha.

    • Bretticus

      Go for it! I’d love to see some CakePHP tuts (seems like the ones on the site are a bit old. Maybe I should go look again. ;-)

    • http://www.findmycourier.com Paulio

      I’d love to see someone put up some decent CakePHP tutorials even just for the comparison. I’m using CI now but I have no idea which framework would be best.

  • http://www.pedrasmachado.com Ricardo Machado

    To say the truth … Although I’ve made a few work using CI the truth is that, the framework, is deprecated ….

    … for a full OOP support… try Kohana… Same thing, but more advanced :)

    • http://www.jeffrey-way.com Jeffrey Way
      Author

      I wouldn’t say that by any means. There’s a reason why it’s one of the most popular PHP frameworks available – if not THE most.

      • Alexander Suraphel

        Jeff Please make download link for the other Tutorials too. I use 56k modem.

  • w1sh

    You’re my favorite person online, Jeffrey. Keep up the excellent work.

    • http://www.jeffrey-way.com Jeffrey Way
      Author

      Thank you!! :) But really, I’m rather boring.

      • Mike Schneider

        Now he’s just fishing for comments =D

        Solid tutorial and I think the depth of the tutorial was a perfect. Not too short and not an overwhelming amount of info.

        Also, maybe I missed it in the video, but how would you go about changing the links from 1,2,3 to 1-4,5-9 and so forth?

  • Mini0n

    Nice! =)

    When will there be an CodeIgniter + jQuery tutorial? That would be awesome!

    • http://www.jeffrey-way.com Jeffrey Way
      Author

      I guess that will be the next one. Lots of votes for CI Ajaxy stuff. :)

      • Mini0n

        You’re the man! xD
        Thanks. These tutorials really help.

        Keep up the awesome work! =)

      • http://www.freshclickmedia.com Shane

        Yeah, I’m up for the jQuery/AJAX stuff. Definitely.

        Fantastic stuff Jeffrey, even if you are boring ;)

      • Damon Sharp

        I would like to place my vote for a return to the previous ci sessions tut, but with database verification for more security. Thanks!

  • Andy

    Jeff,

    Kudos on another great tutorial.

    Would love to start seeing some jQuery thrown in to show Ajax requests and using jQuery to “2.0″ things like pagination.

    Keep up the great work

    • Andy

      And I meant to add… everybody go vote for nettuts in “thenetawards – http://thenetawards.com” as vodcast of the year and blog of the year (otherwise Jeffrey is gonna stop making these great videos!)

      This endorsement has not been sponsored or endorsed by Net.tutsplus.com ;)

      • http://www.jeffrey-way.com Jeffrey Way
        Author

        haha. No – I won’t stop anytime soon. But it sure would be fun to win. :) I think it’s going to come down to us and CSS-Tricks – and they deserve it just as much as we do.

  • Riley

    Just wondering why pagination uses the record number for the paging.

    I made my own paging to be like this http://matrixdigital.com/portfolio/page/2/5 where 2 is actually page 2 and 5 is how many records to show. Second one is actually optional.

    I dunno I guess personal taste but I find it weird to see 80 in query when moving to page 2.

    also I’d like to put my vote in for a cart class tutorial. thnx

    • Bretticus

      Codeigniter wanted to make it as easy as just passing the next offset. I’m sure you could extend the Pagination library to render links this way and then just algorithmically compute the offset before sending it as a parameter.

  • http://www.jsxtech.com Jaspal Singh

    Nice tutorial on implementing the pagination with CodeIgniter.
    Thanks for sharing.

  • http://bestnet.co.nz Kevin

    As usual a good tutorial – keep them coming. Plus I agree with Andy and would love to see some JQuery

  • Javed Gardezi

    Finally its here.. good JW
    i have also seen CI pagination tutorials in this site http://www.weblee.co.uk/ its also detailed.

    I think this is series wise tutorials so i would not skip it!!!

  • http://rizqtech.net rizq

    Finally…… CI Day 7 series…..

    Thanks Jeff ;)

  • http://vinodraut.com Vindo

    Very Useful!!

  • arnold

    Finally a pagination tut… yes Im excited!..thanks jeff…
    you always bring quality tuts in here

  • http://aimadj.blogspot.com aimad

    You Are the Good Sir :)

    tks for all this tutorial i’m view all codeigniter series with you it’s gooe .

  • http://tutorial-city.net Tutorial City

    the tutorial is very good. I would like to see a tutorial on how to create custom helpers/plugins for codeigniter, and maybe use AJAX to take it to the next level.

    Thanks JW ;)

  • http://www.okadadesign.no/blog/ shin

    I just posted “How to use Codeigniter captcha plug-in Part 1″ here.
    http://www.okadadesign.no/blog/?p=276
    Someone may be interested in reading this.

  • http://shakin.ru/ Mike

    Thanks, Jeff! Honestly i was waiting for such tutorial.

  • hary

    where you got that player skin.
    I developed similar skin 2 moths ago.

    • http://www.jeffrey-way.com Jeffrey Way
      Author

      It’s the standard skin from screencast.com.

  • http://www.w2point.com Web 2.0 Tools

    Very nice tutorial, great work…

  • Damon Sharp

    Jeff-

    Thanks for this. Explained very well. One question though. When I use .htaccess to remove the index.php do I need to set the uri_segment to 2? I tried it out yesterday and briefly couldn’t get it to work. I am about to get back into it right now, but if could maybe explain this a little I would appreciate it. Thanks!

    • David Ferguson

      No you wouldn’t. The first URI segment is the controller that is being loaded, the second is the method that is being calling within that Controller, and the 3rd segment on are parameters being passed to that method. Using .htaccess to remove index.php doesn’t change this at all.

      • http://www.jeffrey-way.com Jeffrey Way
        Author

        Correct.

    • Damon Sharp

      Yep, figured that out right after I sent this. It was almost quitting time yesterday when I started to implement this. Didn’t add ‘index’ as the second segment for my base_url config param. All fixed. Thanks for the replies guys.

  • Lowkase

    I recently dried up my pagination code and shoved it in a override class. Here is the code:

    CI =& get_instance();

    // Base configuration
    $config['base_url'] = base_url() . $base_url;
    $config['total_rows'] = $total_rows;
    $config['per_page'] = $per_page;
    $config['uri_segment'] = $uri_segment;

    // Styling
    $config['full_tag_open'] = ”;
    $config['full_tag_close'] = ”;

    // Init
    $this->CI->pagination->initialize($config);

    return $per_page;
    }
    }
    ?>

    Save the file as MY_Pagination.php and shove it in your application/library directory.

    Here is an example of the call:

    $total_rows = $this->pagination->set_pagination(‘index.php/exampleURL/index/’, $this->example_model->select_all_count(20), 3, 10);

    I return the total_rows so that I can shove it into the main select call:

    $data['result'] = $this->example_model->select_all( $total_rows, $this->uri->segment(3));

    If your going to have a lot of pagination strewn about your website then drying up your code into an override class is the way to go.

    I haven’t styled up my pagination yet, but after watching the tutorial I am inspired and it should only take a few minutes.

    Thanks for your hard work on the CI front Jeff.

    Cheers,

    Lowkase

  • Lowkase

    Oops,

    Guess I can’t copy paste an entire class.

    If you want the source for the MY_Pagination.php class just shoot me a quick email.

    Cheers,

    Lowkase

  • joe

    we’ll basically repeat ourselves here jeff,
    you deserve some kinda award for all this man,brilliant

  • David Ferguson

    JW: Wow. You flew through that haha. Not to the point that it made it hard to follow, just seemed a bit more rushed that some of your others. Great tutorial as usual though, there was one thing I wanted to mention/ask though:

    Since you were using the HTML Table library anyway, do you not think it would have been better to use the HTML Table Template option (mentioned in the CI User Guide as Changing the Look of Your Table at http://codeigniter.com/user_guide/libraries/table.html) to define the some of the table characteristics rather than using the css and jQuery to do it all? The main advantage being that, you can style multiple tables within the same page (probably wouldn’t happen, but just in case) using the template rather than having to get really specific with css, and it would eliminate the need for using jQuery to stripe the rows, as CodeIgniter (with the templating) allows you to set the code for row_start and row_alt_start.

    Not a big deal, was just something I thought would have been cool to mention..

    • http://www.jeffrey-way.com Jeffrey Way
      Author

      Hey David. Perhaps. To be honest – I think I mentioned this in the video – but I haven’t used the HTML table class that much.

      You’re right that this one was a bit more rushed. It’s because it was the second run-through. The first version came in at 30 minutes….and I lost the entire thing to my computer freezing up. So painful. :)

  • ali baba

    Jeffrey

    I notice you didn’t use model in this tutorial.

    Is it to save time?

    otherwise great tuts. looking forward to next one

    thanks

    • http://net.tutsplus.com Jeffrey Way

      I did it to demonstrate that CI can be as flexible or strict as you’d like. I would personally have used a model.

      • Ali Baba

        Hey Jeffrey

        When next one comming?

  • David

    As always great tutorial. Looking forward to more.

  • Sunil

    Great Turorial ! PHP community appreciates your contribution…

  • http://aryandelhi.webs.com aryan

    Jeff,

    Next tuts on Ajax with Jquery, plz.

    Thanks for great work.

  • sunil

    Hi Jeff,

    Question :::

    Is there a easy way to sort the the table by clicking the table header ?

    • http://www.jeffrey-way.com Jeffrey Way
      Author

      Not built in – but it wouldn’t be too hard to add.

  • http://www.stookstudio.com Erwin Heiser

    Have a look at jQuery tablesort: http://tablesorter.com/docs/ for sortable tables.
    Great tut as usual Jeffrey, keep’em coming :)

  • http://www.clintonbeattie.com/ Clinton

    Excellent stuff. More Codeigniter tutorials please. Can’t get enough of them at the moment. Be good to see a more thorough build on the login tutorial so you don’t have to rely on CI’s cookies. Maybe integrate it with standard php functions to manage sessions?

    Keep up the sterling work.

  • flux

    I propose a screencast on ajax and methods to integration it in codeigniter… thanks for these useful screencast

  • Javed Gardezi

    can some tell me is there any difference in using
    $config['base_url'] = “http://localhost/ci_nettuts/”;
    or
    $config['base_url'] = “http://localhost/ci_nettuts/index.php/”;

    Well up till now i have seen no difference is it right??

    • http://www.axscollective.com Bryant

      Yea if you go to

      localhost/ci_nettuts/

      it will automatically load the index.php file in that directory

      however, you can change that behavior in the htaccess file so it depends on how you have that configured.

      in a url, after you have index.php..

      the next param is the controller, and then after that is the function in that controller to call. After that all data is treated similar to a query string and lets you pass data.

      so http://localhost/ci_nettuts/index.php/CONTROLLER/FUNCTION/PARAM1/PARAM2/PARAM3/PARAM4/ETC../

  • Dogma

    Jeffrey! Thanks alot for the new screencast! Excellent work!
    My suggestions for the future screencasts is:
    1) template system. as i remember, then i tried CI – it doesn’t have proper template system. i mean, what many another frameworks (yii, cakephp, ruby on rails, etc) have nice layout system. maybe you have any ideas, how to recreate this in CI?
    2) ajax stuff. jquery prefered ^)

  • http://gravityfx.org/ emcgfx

    Hey Jeff, can you please do a video on more database functions like Search, Delete and Form inputs ? Thank you.