Fixed misc bugs...

main
Robert 3 years ago
parent 01540e23f9
commit cc8e7529db
  1. 15
      src/mockup/controllers/app/home_ctrl.php
  2. 9
      src/mockup/go_text_templates/ctrl.txt
  3. 37
      src/mockup/go_text_templates/logic.txt
  4. 36
      src/mockup/go_text_templates/outputs.txt
  5. 2
      src/mockup/go_text_templates/views.txt
  6. 37
      src/mockup/logic/app/home_logic.php
  7. 36
      src/mockup/outputs/app/home_out.php

@ -28,20 +28,11 @@ class home_ctrl {
} }
public function name_demo_post() { public function name_demo_post() {
$input = \prj\mockup\inputs\app\home_in::name_demo(); \tts\main\registry::set('db', \tts\main\registry::get('di')->get_service('db_mocker') );
\tts\main\registry::set('db', \tts\main\registry::get('di')->get_service('db_mocker') ); // Grabs DB $input = \prj\mockup\inputs\app\home_in::name_demo();
$model = new \prj\mockup\models\app\home_model(\tts\main\registry::get('db'));
$model->init_name_demo_table(); // Create Table if NOT exists!
if ($model->is_valid($input)) {
$model->populate(100); // INSERT 100 random rows of data
}
$success = $model->save_new_user($input); // Save user from Users Request Data \prj\mockup\logic\app\home_logic::name_demo($input);
// Only show users 12, if added new one
$input['model'] = ($success===true) ?
$model->get_users(101) :
$model->get_users(0);
$output = \prj\mockup\outputs\app\home_out::name_demo($input); $output = \prj\mockup\outputs\app\home_out::name_demo($input);

@ -13,15 +13,8 @@ class {{.File}}_ctrl {
public function {{.Method}}() { public function {{.Method}}() {
$input = \prj\{{.Root}}\inputs\{{.Subfolder}}\{{.File}}_in::{{.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! \prj\{{.Root}}\logic\{{.Subfolder}}\{{.File}}_logic::{{.Method}}($input);
$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); $output = \prj\{{.Root}}\outputs\{{.Subfolder}}\{{.File}}_out::{{.Method}}($input);

@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace prj\{{.Root}}\logic\{{.Subfolder}};
use \tts\safer_io as SafeIO;
class {{.File}}_logic {
public static function {{.Method}}(array & $input): void {
$model = new \prj\{{.Root}}\models\{{.Subfolder}}\{{.File}}_model(\tts\main\registry::get('db'));
$submitted = true;
foreach(SafeIO::logic_sanitize($input) as $data) {
if (SafeIO::required_fields_were_NOT_all_submitted($data)) {
$submitted = false;
break;
}
}
$input['submitted'] = $submitted;
if ($submitted) {
$model->init_demo_table(); // Create Table if NOT exists!
$model->populate(10); // INSERT 10 random rows of data
$success = $model->save_index($input); // Save data from Request Data
$input['model'] = ($success===true) ?
$model->get_index(15) :
$model->get_index(0);
} else {
$input['model'] = $model->get_index(0);
}
}
}

@ -12,24 +12,30 @@ class {{.File}}_out {
$ret['model'] = $input['model']; $ret['model'] = $input['model'];
unset($input['model']); // Free up some space unset($input['model']); // Free up some space
$html_output = []; $submitted = $input['submitted'] ?? false;
$errors = [];
foreach(SafeIO::html_escape_and_sanitize($input) as $html) {
$key = $html['name'] ?? "";
$html_output[$key] = $html['html'];
if (\tts\common::get_count($html['errors'])) {
$errors[$key] = $html['errors'][$key];
}
}
$age = $html_output['age'] ?? 0; if ($submitted) {
$first_name = $html_output['first_name'] ?? "Unknown"; $html_output = [];
$last_name = $html_output['last_name'] ?? "Unknown"; $errors = [];
foreach(SafeIO::html_escape_and_sanitize($input) as $html) {
$key = $html['name'] ?? "";
$html_output[$key] = $html['html'];
$ret['main'] = (\tts\common::get_count($errors)) ? "" : "Hello {$first_name} {$last_name}, You are {$age} years old!" . PHP_EOL; if (\tts\common::get_count($html['errors'])) {
$ret['errors'] = $errors; $errors[$key] = $html['errors'][$key];
}
}
$age = $html_output['age'] ?? 0;
$first_name = $html_output['first_name'] ?? "Unknown";
$last_name = $html_output['last_name'] ?? "Unknown";
$ret['main'] = (\tts\common::get_count($errors)) ? "" : "Hello, {$first_name} {$last_name}." . PHP_EOL;
$ret['errors'] = $errors;
} else {
$ret['main'] = "Welcome";
$ret['errors'] = [];
}
unset($input); // Free up some space unset($input); // Free up some space

@ -11,6 +11,8 @@ $method_name_demo_post = "{{.Method}}";
echo \prj\{{.Root}}\outputs\{{.Subfolder}}\{{.File}}_out::{{.Method}}_show_errors($output['errors']); echo \prj\{{.Root}}\outputs\{{.Subfolder}}\{{.File}}_out::{{.Method}}_show_errors($output['errors']);
?> ?>
<?= $output['main'] ?>
<br/><br/> <br/><br/>
<form method="post"> <form method="post">
<label for="fname">First Name: <input type="text" id="fname" name="first_name" size="15" /></label><br/> <label for="fname">First Name: <input type="text" id="fname" name="first_name" size="15" /></label><br/>

@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace prj\mockup\logic\app;
use \tts\safer_io as SafeIO;
class home_logic {
public static function name_demo(array & $input): void {
$model = new \prj\mockup\models\app\home_model(\tts\main\registry::get('db'));
$submitted = true;
foreach(SafeIO::logic_sanitize($input) as $data) {
if (SafeIO::required_fields_were_NOT_all_submitted($data)) {
$submitted = false;
break;
}
}
$input['submitted'] = $submitted;
if ($submitted) {
$model->init_name_demo_table(); // Create Table if NOT exists!
$model->populate(10); // INSERT 10 random rows of data
$success = $model->save_new_user($input); // Save data from Request Data
$input['model'] = ($success===true) ?
$model->get_users(15) :
$model->get_users(0);
} else {
$input['model'] = $model->get_users(0);
}
}
}

@ -12,24 +12,30 @@ class home_out {
$ret['model'] = $input['model']; $ret['model'] = $input['model'];
unset($input['model']); // Free up some space unset($input['model']); // Free up some space
$html_output = []; $submitted = $input['submitted'] ?? false;
$errors = [];
foreach(SafeIO::html_escape_and_sanitize($input) as $html) {
$key = $html['name'] ?? "";
$html_output[$key] = $html['html'];
if (\tts\common::get_count($html['errors'])) {
$errors[$key] = $html['errors'][$key];
}
}
$age = $html_output['age'] ?? 0; if ($submitted) {
$first_name = $html_output['first_name'] ?? "Unknown"; $html_output = [];
$last_name = $html_output['last_name'] ?? "Unknown"; $errors = [];
foreach(SafeIO::html_escape_and_sanitize($input) as $html) {
$key = $html['name'] ?? "";
$html_output[$key] = $html['html'];
$ret['main'] = (\tts\common::get_count($errors)) ? "" : "Hello {$first_name} {$last_name}, You are {$age} years old!" . PHP_EOL; if (\tts\common::get_count($html['errors'])) {
$ret['errors'] = $errors; $errors[$key] = $html['errors'][$key];
}
}
$age = $html_output['age'] ?? 0;
$first_name = $html_output['first_name'] ?? "Unknown";
$last_name = $html_output['last_name'] ?? "Unknown";
$ret['main'] = (\tts\common::get_count($errors)) ? "" : "Hello, {$first_name} {$last_name}, you are {$age} years old!" . PHP_EOL;
$ret['errors'] = $errors;
} else {
$ret['main'] = "Welcome";
$ret['errors'] = [];
}
unset($input); // Free up some space unset($input); // Free up some space

Loading…
Cancel
Save