From 2b577469230db0e7a2515248dbf457a85bdaf593 Mon Sep 17 00:00:00 2001 From: Aleksandr Shelkovin Date: Mon, 13 Jan 2025 21:48:57 +0300 Subject: [PATCH] mvc --- cristmass-tree/index.php | 3 +- engine/Route.php | 8 +++ engine/app/controller/AboutController.php | 6 ++ engine/index.php | 79 ++++++++++++++--------- engine/index_2.php | 35 ++++++++++ engine/mvc.php | 27 -------- engine/stack.php | 31 +++++++++ 7 files changed, 131 insertions(+), 58 deletions(-) create mode 100644 engine/Route.php create mode 100644 engine/app/controller/AboutController.php create mode 100644 engine/index_2.php delete mode 100644 engine/mvc.php create mode 100644 engine/stack.php diff --git a/cristmass-tree/index.php b/cristmass-tree/index.php index 5b23d49..aa9b4e9 100644 --- a/cristmass-tree/index.php +++ b/cristmass-tree/index.php @@ -1,6 +1,7 @@ drawTree(); + diff --git a/engine/Route.php b/engine/Route.php new file mode 100644 index 0000000..4996679 --- /dev/null +++ b/engine/Route.php @@ -0,0 +1,8 @@ +route = 'admin'; + } +} \ No newline at end of file diff --git a/engine/app/controller/AboutController.php b/engine/app/controller/AboutController.php new file mode 100644 index 0000000..0bccc25 --- /dev/null +++ b/engine/app/controller/AboutController.php @@ -0,0 +1,6 @@ +$action(); + + + +class MainModel { - extract($data); - - - // include "model_box.php"; - - // Start output buffering - ob_start(); - - // Include the template file - include FOLDER_TEMPLATE . $tpl; - - // Get the contents of the buffer - $content = ob_get_contents(); - - // End output buffering and erase the buffer's contents - ob_end_clean(); - - // Perform any necessary processing on the template content -// For example, you can replace placeholders, apply filters, etc. -// $content = str_replace('{{title}}', 'My Website', $content); - - // Output the processed content - return $content; + public function getData() + { + return [ + 'title' => 'Main Page', + 'h3' => 'С новым годом!' + ]; + } +} +class MainController +{ + public function index() + { + $model = new MainModel(); + $view = new MainView(); + $result = $model->getData(); + $view->render($result, 'main.tpl'); + } +} +class MainView +{ + public function render($data, $tmpl) + { + var_dump($data); + } } -$value = ['box' => $box, 'title' => "God save the King!", 'body' => "Happy New Year!", 'auth' => false]; -$portial = render('tpl_layout.php', $value); - -echo $portial; \ No newline at end of file +$cont = new Route(''); diff --git a/engine/index_2.php b/engine/index_2.php new file mode 100644 index 0000000..07fe100 --- /dev/null +++ b/engine/index_2.php @@ -0,0 +1,35 @@ + $box, 'title' => "God save the King!", 'body' => "Happy New Year!", 'auth' => false]; +$portial = render('tpl_layout.php', $value); + +echo $portial; \ No newline at end of file diff --git a/engine/mvc.php b/engine/mvc.php deleted file mode 100644 index b2ff9f6..0000000 --- a/engine/mvc.php +++ /dev/null @@ -1,27 +0,0 @@ - 'Main Page', - 'h3' => 'С новым годом!']; - } -} -class MainController { - public function index() - { - $model = new MainModel(); - $view = new MainView(); - $result = $model->getData(); - $view->render($result, 'main.tpl'); - } -} -class MainView { - public function render($data, $tmpl) - { - var_dump($data); - } -} - -$controll = new MainController(); -$controll->index(); \ No newline at end of file diff --git a/engine/stack.php b/engine/stack.php new file mode 100644 index 0000000..8bd7bfa --- /dev/null +++ b/engine/stack.php @@ -0,0 +1,31 @@ +_lifo[] = $value; + } + + public function pop() { + $max_size = sizeof($this->_lifo); + if ($max_size == 0 ) return NULL; + // var_dump($max_size); + $val = $this->_lifo[$max_size - 1]; + unset($this->_lifo[$max_size -1 ]); + return $val; + } +} + +$stack = new Lifo(); +$stack->push(199); +$stack->push(200); +$stack->push(-234); +var_dump($stack->_lifo); +$v = $stack->pop(); +$v = $stack->pop(); +$v = $stack->pop(); +var_dump($v); + +//assert( $v == -235, new StackError('Ошибка стека!!!'));