About this example : Hello Word Second

Controller

controllers/examples/cms/HelloWorldSecond.php

<?php

namespace controllers\examples\cms;

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

class HelloWorldSecond extends Controller
{

    /**
     * Constructor.
     */
    public function __construct()
    {
        $this->model = new HelloWorldModel();
        $this->view = new HelloWorldView();
        $this->view->loadCustomTemplate("templates/examples/cms/hello_world_second");
        parent::__construct($this->view,$this->model);
    }

    /**
     * Autorun method. Put your code here for running it after object creation.
     * @param mixed|array|null $parameters Additional parameters for generic purpose.
     *
     */
    protected function autorun($parameters = null)
    {
        $modelData = $this->model->getMessage();
        $message = empty($parameters) ? $modelData : $parameters;
        $this->view->setMessage($message);

        try {
            $this->view->setVar("SITEURL",SITEURL);
        } catch (Exception $e) {
        }


    }

    /**
     * Sets a mobile GUI
     * @param null $withMessage If present show it as a message
     */
    public function mobile($withMessage=null)
    {
        $this->view->loadCustomTemplate("templates/examples/cms/hello_world_mobile");
        $this->autorun($withMessage);
        $this->render();
    }

    /**
     * Shows the given message
     * @param string $m
     */
    public function message($m)
    {
        $this->autorun($m);
        $this->render();
    }

}

Model

models/examples/cms/HelloWorld.php (Shared)

<?php

namespace models\examples\cms;

use framework\Model;

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

View

views/examples/cms/HelloWorld.php (Shared)

<?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_second.html.tpl

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

    <p>This example shows the basic use of framework for acting a GUI
        design replacement</p>
    <p>It also shows the usage for calling public methods with parameters
        developed inside the controller,</p>

    <h3>{Message}</h3>

    <ul>
        <li><a href="{SITEURL}/examples/cms/hello_world_second">Main</a></li>
        <li><a href="{SITEURL}/examples/cms/hello_world_second/mobile/">Switch to a mobile design</a></li>
        <li><a href="{SITEURL}/examples/cms/hello_world_second/message/Hi All">Call a method message with a parameter</a></li>
        <li><a href="{SITEURL}/examples/cms/hello_world_second/mobile/Hello Mobile GUI">Call a method message inside mobile design</a></li>
        <li><a href="{SITEURL}/examples/cms/controller_demo">Exception: Controller not found</a></li>
        <li><a href="{SITEURL}/examples/cms/hello_world_second/new_method">Exception: Method to found</a></li>
        <li><a href="{SITEURL}/examples/cms/hello_world_second/message/Param1/Param2">Exception: Parameters errors</a></li>
        <li><a href="{SITEURL}/examples/">Examples TOC</a></li>
    </ul>
    <a href="../about/example/helloWorldSecond" class="btn btn-info">Show source code</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