About this example : PartList MVC Assembly source Code

Controller

controllers/examples/db/PartList.php

<?php
/**
 * Class PartList
 *
 * {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\PartList as PartListModel;
use views\examples\db\PartList as PartListView;
use controllers\examples\cms\NavigationBar;
use framework\components\DataRepeater;


class PartList extends Controller
{
    /**
    * Object constructor.
    *
    * @param View $view
    * @param Model $mode
    */
    public function __construct(View $view=null, Model $model=null)
    {
        $this->view = empty($view) ? $this->getView() : $view;
        $this->model = empty($model) ? $this->getModel() : $model;
        parent::__construct($this->view,$this->model);
        $navigation = new NavigationBar();
        $this->bindController($navigation);
        $this->setAsObserver("parts", true, "myCallBack()");
    }


    protected function autorun($parameters = null)
    {
        $this->view->setBlockParts($this->model->getResultSet());
    }

    /**
     * Use a DataRepeater to simplify the job
     */
    public function useRepeater()
    {
        $parts = new DataRepeater($this->view,$this->model,"Parts",null);
        $this->bindComponent($parts);
        $this->render();
    }

    /**
    * Inizializes the View
    */
    public function getView()
    {
        $view = new PartListView("/examples/db/part_list");
        return $view;
    }

    /**
    * Inizializes the Model
    */
    public function getModel()
    {
        $model = new PartListModel();
        return $model;
    }
}

Model

models/examples/db/PartList.php

<?php

namespace models\examples\db;

use framework\Model;

class PartList extends Model
{
    public function __construct()
    {
        parent::__construct();
        $this->sql = "SELECT * FROM part";
        $this->updateResultSet();
    }

}

View

views/examples/db/PartList.php

<?php

namespace views\examples\db;

use framework\View;

class PartList extends View
{
    public function __construct($tplName = null)
    {
        if (empty($tplName))
            $tplName = "/examples/db/part_list";
        parent::__construct($tplName);
    }

    public function setBlockParts(\mysqli_result $resultset){
        $this->openBlock("Parts");
        while ($part = $resultset->fetch_object()) {
            $this->setVar("part_code",$part->part_code);
            $this->setVar("description",$part->description);
            $this->setVar("source",$part->source);
            $this->setVar("source_lead_time",$part->source_lead_time);
            $this->setVar("measurement_unit_code",$part->measurement_unit_code);
            $this->setVar("part_type_code",$part->part_type_code);
            $this->setVar("part_category_code",$part->part_category_code);
            $this->setVar("wastage",$part->wastage);
            $this->setVar("bom_levels",$part->bom_levels);
            $this->parseCurrentBlock();
        }
        $this->setBlock();
    }
}

HTML Template

templates/examples/db/part_list.html.tpl

<!DOCTYPE html>
<html>
<head>
    <title>Part listing</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" id="parts">
            <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">{RES:AllParts}</td>
                </tr>
            </tfoot>
        </table>

        <hr>
        <a href="https://www.webmvcframework.com/webmvc/examples/about/example/partList" 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>
<script>
    function myCallBack() {
        console.log("Call back from custom call back");
    }

    function observerCallBack() {
        console.log("Call back from observer");
    }
</script>
</body>
</html> 


Back