Bummer! This is just a preview. You need to be signed in with a Treehouse account to view the entire video.
Getting the Count of Products0:51 with Randy Hoyt
We will walk through the controller code for this new feature first, but we'll need to have a simple function in our model that we can call. In this video, we discuss how that get_products_count() function needs to work.
We have identified everything we'll need to add in our model, our view,
and our controller code for this new pagination feature.
I typically like to start with the model code,
and then work my way forward to the controller code and the view code.
However, the get product subset function will be a little tricky,
and I think it will be best to explain it after we've written the controller code that calls it.
But I suspect you'll be able to handle the get products count function on your own.
Go ahead and add a new function to your products include file called get products count.
This should return to the controller the total number of products,
so that the controller can figure out how many pages there are.
This should call our existing get products all function
and return the number of elements in that product's array.
You can download the final project code for this video if you need a little help,
but give it a try on your own first. We'll start using it shortly.
You need to sign up for Treehouse in order to download course files.Sign up