<?php

declare(strict_types=1);

namespace ex\controllers\app;

class home_ctrl {
    
//  public function skip_default_error_handler() {} 
    
  public function index_cli() { echo "See: /ex/cronjobs/daily/index"; }
    
  public function index() {
      $html = new \tts\html_document();

      $view = new \tts\view();
      $view->set('html', $html);
      $view->set_template('main');
      $view->include("app/header");
      $view->include("app/footer");
      $view->render($this, "app/home_index");
  }
    
  public function name_demo() {      
      $input = \ex\inputs\app\home_in::name_demo();

      \tts\main\registry::set('db', \tts\main\registry::get('di')->get_service('db_mocker') ); // Grabs DB
      $model = new \ex\models\app\home_model(\tts\main\registry::get('db')); 
      $model->init_name_demo_table(); // Create Table if NOT exists!
      $model->populate(10); // INSERT 10 random rows of data
      $model->save_new_user($input); // Save user from Users Request Data
            
      $input['model'] = $model->get_users();

      $output = \ex\outputs\app\home_out::name_demo($input);
//asd();
      $html = new \tts\html_document();
      $html->set_footer('<br/><br/><hr/>By BBV-Soft');
      
      $view = new \tts\view();
      $view->set('html', $html); // set view's local variables
      $view->set_template('main');
      $view->set('output', $output);
      $view->include("app/name_demo"); // Alias to add_view/set_view
      $view->render($this);
  }
  
  public function error() { tts_broken_error(); } // Needed: To show Live Page for Broken Pages

}