<?php

namespace prj\{{.Root}}\controllers\{{.Subfolder}};

class {{.File}}_ctrl {

  public function __construct() {
    \tts\main\registry::set('db', \tts\main\registry::get('di')->get_service('db_mocker') );
  }

  public function {{.Method}}() {
    $input = \prj\{{.Root}}\inputs\{{.Subfolder}}\{{.File}}_in::{{.Method}}();
    $model = new \prj\{{.Root}}\models\{{.Subfolder}}\{{.File}}_model(\tts\main\registry::get('db')); 

    $model->init_demo_table(); // Create Table if NOT exists!
    $model->populate(10); // INSERT 10 random rows of data

    $success = $model->save_{{.Method}}($input); // Save data from Request Data
    $input['model'] = ($success===true) ? 
          $model->get_{{.Method}}(15) : 
          $model->get_{{.Method}}(0);

    $output = \prj\{{.Root}}\outputs\{{.Subfolder}}\{{.File}}_out::{{.Method}}($input);
    
    $html = new \tts\html_document();
    $view = new \tts\view();
    $view->set('html', $html);
    $view->set('output', $output);
    $view->set_template('main');
    $view->include("{{.Subfolder}}/{{.File}}_{{.Method}}_view");
    $view->render($this);
  }
}