Architecture

Hugonette micro-framework is designed on the Model-View-Presenter pattern. Your task is to determine the view, calculate model (the array of data), and pass it to the presenter.

View

You can set several view types: JSON microservices, upload or redirect are helpful. But the main view type will be Latte, which is a template engine from Nette framework. Be sure to review their short documentation to see what you can do with this powerful tool.

To see famous 'Hello World', we will use Latte view. First prepare a basic template. You don't need Hugo to do this. Edit any index.html file or make a fresh one, placing inside {$hello} code. This is the command to print the value of variable $hello. Put the file in www/static/myblog folder.

Model

To prepare data for your page you will work inside the app folder of your project. We have nothing to calculate now, because our Model is 'Hello World' only.

But take a look at some useful files, which are already there to direct your data flow.

  • Bootstrap.php -- initial configuration of the environment

  • routes.php -- you will need to define some routes here, but now you have what you need:

Env::set('view', 'latte');  // Latte view
$route->get('/', 'Examples'); // route to 'default' method of 'Examples' presenter class
$route->get('/login/.*', 'Examples:login'); // route to 'login' method of 'Examples' presenter class

Latte view is set to make use of a template you've made. Next you see some routes to Presenter.

Presenter

The aim of Presenter is to gather all the data to be presented by View

Go to app/presenters folder and see Examples.php class. The default method of this class is expected to return a Model. In this example we return 'hello' key to have it inside the template as $hello variable.

protected function default()
{
  return [
    'hello' => 'Hello world',
  ];
}

Now type the address into your browser: http://localhost/myblog -- and you will see Hello world. But if you made any mistake, Tracy debugging tool would show you what to fix. So... make a mistake now to see Tracy in action.

Last updated