mvc
This commit is contained in:
parent
4da85dd434
commit
2b57746923
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
include_once ('tree.php');
|
||||
include_once('tree.php');
|
||||
|
||||
$cristmassTree = new Tree(25);
|
||||
$cristmassTree->drawTree();
|
||||
|
||||
|
8
engine/Route.php
Normal file
8
engine/Route.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
class Route
|
||||
{
|
||||
public $route;
|
||||
public function __construct() {
|
||||
$this->route = 'admin';
|
||||
}
|
||||
}
|
6
engine/app/controller/AboutController.php
Normal file
6
engine/app/controller/AboutController.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
class AboutController {
|
||||
public function index() {
|
||||
print ("AboutController");
|
||||
}
|
||||
}
|
@ -1,35 +1,54 @@
|
||||
<?php
|
||||
|
||||
define('FOLDER_TEMPLATE', './template/');
|
||||
include "model_box.php";
|
||||
function render($tpl, $data)
|
||||
spl_autoload_register(function ($class_name) {
|
||||
$dir = ['/app/controller'];
|
||||
foreach ($dir as $path) {
|
||||
$path = __DIR__ . $path . $class_name . '.php';
|
||||
include $path;
|
||||
}
|
||||
});
|
||||
|
||||
var_dump($_SERVER['REQUEST_URI']);
|
||||
$uri = trim($_SERVER['REQUEST_URI'], '/');
|
||||
|
||||
$mass_uri = explode('/', $uri);
|
||||
var_dump($mass_uri);
|
||||
|
||||
$controller = $mass_uri[0];
|
||||
$action = $mass_uri[1] ? $mass_uri[1] : 'index';
|
||||
$nameClassController = ucfirst($controller) . 'Controller';
|
||||
|
||||
$cntr = new $nameClassController;
|
||||
$cntr->$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;
|
||||
$cont = new Route('');
|
||||
|
35
engine/index_2.php
Normal file
35
engine/index_2.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
define('FOLDER_TEMPLATE', './template/');
|
||||
include "model_box.php";
|
||||
function render($tpl, $data)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
$value = ['box' => $box, 'title' => "God save the King!", 'body' => "Happy New Year!", 'auth' => false];
|
||||
$portial = render('tpl_layout.php', $value);
|
||||
|
||||
echo $portial;
|
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
class MainModel {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
$controll = new MainController();
|
||||
$controll->index();
|
31
engine/stack.php
Normal file
31
engine/stack.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
class StackError extends AssertionError {}
|
||||
|
||||
class Lifo {
|
||||
public $_lifo = [];
|
||||
|
||||
public function push($value) {
|
||||
$this->_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('Ошибка стека!!!'));
|
Loading…
Reference in New Issue
Block a user