About this example : Hello Word

Controller

controllers/examples/cms/HelloWorld.php

<?php

namespace controllers\examples\cms;

use 
framework\Controller;
use 
models\examples\cms\HelloWorld as HelloWorldModel;
use 
views\examples\cms\HelloWorld as HelloWorldView;


/**
 * Class HelloWorld
 * @package controllers\examples\cms
 */
class HelloWorld extends Controller
{

    public function 
__construct(View $view=nullModel $model=null)
    {
        
$this->model = new HelloWorldModel();
        
$this->view = new HelloWorldView();
        
parent::__construct($this->view,$this->model);
    }

    protected function 
autorun($parameters null)
    {

        
// Gets some data from Model
        
$modelData $this->model->getMessage();

        
// Run some method of the View by passing it some data (from Model)
        
$this->view->setMessage($modelData);

    }

}

Model

models/examples/cms/HelloWorld.php

<?php

namespace models\examples\cms;

use 
framework\Model;

class 
HelloWorld extends Model
{
    
/**
     * Gets a simple message.
     * @return string
     */
    
public function getMessage()
    {
        return 
"Hello World from PHP Web MVC Framework";
    }
}

View

views/examples/cms/HelloWorld.php

<?php

namespace views\examples\cms;

use 
framework\View;

class 
HelloWorld 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/cms/hello_world";
        
parent::__construct($tplName);
    }

    
/**
     * Set  Message PlaceHolder with a given value
     *
     * @param string $msg
     */
    
public function setMessage($msg){
        
$this->setVar("Message",$msg);
    }
    
}

HTML Template

templates/examples/cms/hello_world.html.tpl

<!DOCTYPE html>
<html>
<head>
    <title>Hello World Example</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>

<div class="container">
    <h1>Web MVC Framework</h1>
    <h2>Hello World</h2>
    <p>
        This example shows the basic concept for data communication among all the MVC layers.<br>
        It uses a simple <strong>placeholder</strong>, located inside of the GUI static design,
        for placing data provided from model and through the following control flow:<br><br>
    </p>
    <div class="well">
        <ol class="h5">
            <li>HTTP Request => Dispatcher => Controller</li>
            <li>Model <=> Controller <=> View <= Template</li>
            <li>Controller => Dispatcher => Response</li>
        </ol>
    </div>
    <p> 1) and 3) are automatically handled by the framework dispatcher</p>
    <p> 2) is made by extending the Framework Classes (Controller,Model,View)and by consuming their services</p>

    <h3>{Message}</h3>
    <br /><br />

    <a href="https://www.webmvcframework.com/examples/about/example/hello_world" class="btn btn-info">Show source code</a>
    <a href="https://www.webmvcframework.com/examples/cms/hello_world/" class="btn btn-success">Template</a>
    <a href="https://www.webmvcframework.com/examples/cms/hello_world" class="btn btn-success">Run again</a>
    <a href="https://www.webmvcframework.com/examples/" class="btn btn-primary">Examples TOC</a>

</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