Kumail
Kumail

Reputation: 21

Pagination in PHP MVC

I've written a small MVC in PHP5 and desire a pagination module to be added to some files in my views section/folder..

I was wondering.. would the Pagination class be included in the Controller or Models section/folder?

Currently i've included it in the Models folder and called the function when needed..

Upvotes: 2

Views: 3550

Answers (3)

littlechad
littlechad

Reputation: 1228

i guess the best approach is to call the pagination from the view, referring to this MVC

A view queries the model in order to generate an appropriate user interface (for example the view lists the shopping cart's contents). The view gets its own data from the model. In some implementations, the controller may issue a general instruction to the view to render itself. In others, the view is automatically notified by the model of changes in state (Observer) that require a screen update.

and because you will be using this class almost in every view, you should make a helper and include this class inside that helper so that all the views can share its methods

Upvotes: 0

Stanislav Shabalin
Stanislav Shabalin

Reputation: 19278

The way I see it, pagination is a control, allowing user to tell your database (model), which portion of data he or she wants to see.

So I would go with the Controllers module.

Upvotes: 2

BebliucGeorge
BebliucGeorge

Reputation: 751

Well, I think a better approach would be to make a helpers folder and then load them into your application like this :

function use_helper()
{
    static $helpers = array();

    foreach (func_get_args() as $helper)
    {
        if (in_array($helper, $helpers)) continue;

        $helper_file = HELPER_PATH.DIRECTORY_SEPARATOR.$helper.'.php';

        if (!file_exists($helper_file))
            throw new Exception("Helper file '{$helper}' not found!");

        include $helper_file;
        $helpers[] = $helper;
    }
} 

Then all you have to do is build a pagination.php file with your Pagination class. When you need it, you call the function

use_helper('pagination');

From here of course it depends on you Pagination class. Hope this helps.

Upvotes: 1

Related Questions