About this example : PartPaginator MVC Assembly source Code

Controller

controllers/examples/db/PartPaginator.php

<?php
/**
 * Class PartPaginator
 *
 * {ControllerResponsability}
 *
 * @package controllers\examples\db
 * @category Application Controller
 * @author  {AuthorName} - {AuthorEmail}
*/
namespace controllers\examples\db;

use framework\Controller;
use framework\Model;
use framework\View;
use models\examples\db\PartPaginator as PartPaginatorModel;
use views\examples\db\PartList as PartListView;
use controllers\examples\cms\NavigationBar;
use framework\components\DataRepeater;
use framework\components\bootstrap\PaginatorBootstrap;

class PartPaginator extends Controller
{
    /**
    * Object constructor.
    *
    * @param View $view
    * @param Model $mode
    */
    public function __construct()
    {
        $this->model = $this->getModel();
        $this->view = $this->getView();
        parent::__construct($this->view,$this->model);
        $navigation = new NavigationBar();
        $this->bindController($navigation);
    }


    protected function autorun($parameters = null)
    {

        $paginator = new PaginatorBootstrap();

        $paginator->setName("Bottom");
        $paginator->resultPerPage = 5;
        $paginator->setModel($this->model);
        $paginator->buildPagination();

        $this->model->sql = $paginator->query;

        $parts = new  DataRepeater($this->view,$this->model,"Parts",null);

        $this->bindComponent($paginator);
        $this->bindComponent($parts);
    }

    /**
    * Inizialize the View by loading static design of /examples/db/part_paginator.html.tpl
    * managed by views\examples\db\PartPaginator class
    *
    */
    public function getView()
    {
        $view = new PartListView("/examples/db/part_paginator");
        return $view;
    }

    /**
    * Inizialize the Model by loading models\examples\db\PartPaginator class
    *
    */
    public function getModel()
    {
        $model = new PartPaginatorModel();
        return $model;
    }
}

Model

models/examples/db/PartPaginator.php

<?php
/**
 * Class PartPaginator
 *
 * {ModelResponsability}
 *
 * @package models\examples\db
 * @category Application Model
 * @author  {AuthorName} - {AuthorEmail}
*/
namespace models\examples\db;

use framework\Model;

class PartPaginator extends Model
{
    public function __construct()
    {
        parent::__construct();
        $this->sql =
<<<SQL
            SELECT  
              part_code, 
              description, 
              source, 
              source_lead_time, 
              measurement_unit_code, 
              part_type_code, 
              part_category_code, 
              wastage, 
              bom_levels 
            FROM 
              part
SQL;
        // Also this
        // $this->sql = "SELECT t.* FROM part t";
        $this->updateResultSet();
    }
}

View

views/examples/db/PartPaginator.php

<?php
/**
 * Class PartPaginator
 *
 * {ViewResponsability}
 *
 * @package controllers\examples\db
 * @category Application View
 * @author  {AuthorName} - {AuthorEmail}
*/
namespace views\examples\db;

use framework\View;

class PartPaginator extends View
{

    /**
    * Object constructor.
    *
    * @param string|null $tplName The html template containing the static design.
    */
    public function __construct($tplName = null)
    {
        if (empty($tplName))
            $tplName = "/examples/db/part_paginator";
        parent::__construct($tplName);
    }
    
}

HTML Template

templates/examples/db/part_paginator.html.tpl

<!DOCTYPE html>
<html>
<head>
    <title>Listing and paginating</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <!-- Bootstrap core CSS -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" media="screen">

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.js"></script>
    <![endif]-->
</head>
<body>
{Controller:examples\cms\NavigationBar}
<div class="container">
    <h1>{RES:PartsList}</h1>
    <div class="table table-responsive">
        <table class="table table-bordered">
            <thead>
            <tr>
                <th>{RES:part_code}</th>
                <th>{RES:description}</th>
                <th>{RES:source}</th>
                <th>{RES:source_lead_time}</th>
                <th>{RES:measurement_unit_code}</th>
                <th>{RES:part_type_code}</th>
                <th>{RES:part_category_code}</th>
                <th>{RES:wastage}</th>
                <th>{RES:bom_levels}</th>
            </tr>
            </thead>
            <tbody>
            <!-- BEGIN Parts -->
            <tr>
                <td>{part_code}</td>
                <td>{description}</td>
                <td>{source}</td>
                <td>{source_lead_time}</td>
                <td>{measurement_unit_code}</td>
                <td>{part_type_code}</td>
                <td>{part_category_code}</td>
                <td>{wastage}</td>
                <td>{bom_levels}</td>
            </tr>
            <!-- END Parts -->
            </tbody>
            <tfoot>
            <tr>
                <td class = "text-center" colspan="9">{PaginatorBootstrap:Bottom}</td>
            </tr>
            </tfoot>
        </table>
        <a href="https://www.webmvcframework.com/webmvc/examples/about/example/partPaginator" class="btn btn-info">Mostra codice sorgente</a>
        <a href="https://www.webmvcframework.com/webmvc/examples/db/part_list/" class="btn btn-success">Mostra il template</a>
        <a href="https://www.webmvcframework.com/webmvc/examples/db/part_list" class="btn btn-success">Ricarica</a>
        <a href="https://www.webmvcframework.com/webmvc/examples/" class="btn btn-primary">Indice degli esempi</a>
    </div>

</div>

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/js/bootstrap.min.js"></script>
</body>
</html> 


Back