mvc again
This commit is contained in:
parent
efacc52ddc
commit
2812b5e9d8
@ -606,6 +606,10 @@ video {
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.h-screen {
|
||||||
|
height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
.min-h-screen {
|
.min-h-screen {
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
}
|
}
|
||||||
@ -634,6 +638,10 @@ video {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.items-center {
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
.justify-center {
|
.justify-center {
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
@ -729,6 +737,11 @@ video {
|
|||||||
line-height: 2.25rem;
|
line-height: 2.25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.text-6xl {
|
||||||
|
font-size: 3.75rem;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
.text-sm {
|
.text-sm {
|
||||||
font-size: 0.875rem;
|
font-size: 0.875rem;
|
||||||
line-height: 1.25rem;
|
line-height: 1.25rem;
|
||||||
@ -764,6 +777,11 @@ video {
|
|||||||
letter-spacing: 0.025em;
|
letter-spacing: 0.025em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.text-blue-500 {
|
||||||
|
--tw-text-opacity: 1;
|
||||||
|
color: rgb(59 130 246 / var(--tw-text-opacity, 1));
|
||||||
|
}
|
||||||
|
|
||||||
.text-gray-500 {
|
.text-gray-500 {
|
||||||
--tw-text-opacity: 1;
|
--tw-text-opacity: 1;
|
||||||
color: rgb(107 114 128 / var(--tw-text-opacity, 1));
|
color: rgb(107 114 128 / var(--tw-text-opacity, 1));
|
||||||
@ -799,6 +817,11 @@ video {
|
|||||||
color: rgb(126 34 206 / var(--tw-text-opacity, 1));
|
color: rgb(126 34 206 / var(--tw-text-opacity, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.text-red-500 {
|
||||||
|
--tw-text-opacity: 1;
|
||||||
|
color: rgb(239 68 68 / var(--tw-text-opacity, 1));
|
||||||
|
}
|
||||||
|
|
||||||
.text-white {
|
.text-white {
|
||||||
--tw-text-opacity: 1;
|
--tw-text-opacity: 1;
|
||||||
color: rgb(255 255 255 / var(--tw-text-opacity, 1));
|
color: rgb(255 255 255 / var(--tw-text-opacity, 1));
|
||||||
|
15
engine/app/controller/MainController.php
Normal file
15
engine/app/controller/MainController.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once __DIR__ . "/../model/AboutModule.php";
|
||||||
|
require_once __DIR__ . "/../view/View.php";
|
||||||
|
|
||||||
|
class MainController
|
||||||
|
{
|
||||||
|
public function actionNotFound()
|
||||||
|
{
|
||||||
|
// $result = AboutModel::getData();
|
||||||
|
// var_dump($result);
|
||||||
|
echo (View::render([], '404.php'));
|
||||||
|
// print("AboutController, А кто то почувствовал перерыв?");
|
||||||
|
}
|
||||||
|
}
|
23
engine/app/template/404.php
Normal file
23
engine/app/template/404.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/4.0.0-beta.9/lib.min.js"></script> -->
|
||||||
|
<link rel="stylesheet" href="./../../app/assets/css/styles.css">
|
||||||
|
<title>Page Not Found</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div className="flex flex-col items-center justify-center h-screen bg-gray-100">
|
||||||
|
<h1 className="text-6xl font-bold text-red-500">404</h1>
|
||||||
|
<p className="mt-4 text-xl">Oops! Page Not Found</p>
|
||||||
|
<a href="/" className="mt-6 text-blue-500 hover:underline">
|
||||||
|
Go to Homepage
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
@ -2,15 +2,8 @@
|
|||||||
|
|
||||||
define('FOLDER_TEMPLATE', __DIR__ .'/../template/');
|
define('FOLDER_TEMPLATE', __DIR__ .'/../template/');
|
||||||
|
|
||||||
class View
|
class View {
|
||||||
{
|
static function render( $data, $tpl ) {
|
||||||
static function render()
|
|
||||||
{
|
|
||||||
|
|
||||||
// include "model_box.php";
|
|
||||||
|
|
||||||
function render($data, $tpl )
|
|
||||||
{
|
|
||||||
extract($data);
|
extract($data);
|
||||||
// Start output buffering
|
// Start output buffering
|
||||||
ob_start();
|
ob_start();
|
||||||
@ -22,5 +15,6 @@ class View
|
|||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -6,6 +6,7 @@ class Autoloader
|
|||||||
spl_autoload_register(function ($class_name) {
|
spl_autoload_register(function ($class_name) {
|
||||||
// print('auto: ' . $class_name);
|
// print('auto: ' . $class_name);
|
||||||
$dir = ['/../app/controller/'];
|
$dir = ['/../app/controller/'];
|
||||||
|
// print($dir);
|
||||||
foreach ($dir as $path) {
|
foreach ($dir as $path) {
|
||||||
$path = __DIR__ . $path . $class_name . '.php';
|
$path = __DIR__ . $path . $class_name . '.php';
|
||||||
if (file_exists($path)) {
|
if (file_exists($path)) {
|
||||||
|
@ -2,51 +2,54 @@
|
|||||||
require_once 'Autoloader.php';
|
require_once 'Autoloader.php';
|
||||||
Autoloader::init();
|
Autoloader::init();
|
||||||
|
|
||||||
|
require_once __DIR__ . "/../../engine/app/view/View.php";
|
||||||
|
|
||||||
class Router
|
class Router
|
||||||
{
|
{
|
||||||
// массив маршрутов
|
|
||||||
private $routes;
|
private $routes;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
// указываем путь к роутам (ROOT - путь к базовой дериктории
|
|
||||||
// '/config/routes.php' - путь к созданному файлу с роутами
|
|
||||||
$routesPath = __DIR__ . '/../routes.php';
|
$routesPath = __DIR__ . '/../routes.php';
|
||||||
|
|
||||||
// здесь мы присваиваем свойству $this->routes массив,
|
|
||||||
// который хранится в файле routes.php, при помощи - include
|
|
||||||
$this->routes = include($routesPath);
|
$this->routes = include($routesPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// метод будет принимать управление от фронтконтроллера
|
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
echo ("Запуск контроллера!");
|
|
||||||
// var_dump($this->routes);
|
|
||||||
// обратимся к методу getURI()
|
|
||||||
$uri = $this->getURI();
|
$uri = $this->getURI();
|
||||||
echo $uri;
|
$controllerName = "";
|
||||||
|
|
||||||
foreach ($this->routes as $uriPattern => $path) {
|
foreach ($this->routes as $uriPattern => $path) {
|
||||||
// echo "<br>$uriPattern -> $path";
|
|
||||||
if (preg_match("~$uriPattern~", $uri)) {
|
if (preg_match("~$uriPattern~", $uri)) {
|
||||||
$segments = explode('/', $path);
|
$segments = explode('/', $path);
|
||||||
$controllerName = array_shift($segments) . 'Controller';
|
$controllerName = array_shift($segments) . 'Controller';
|
||||||
// делает первую букву строки заглавной
|
|
||||||
$controllerName = ucfirst($controllerName);
|
$controllerName = ucfirst($controllerName);
|
||||||
var_dump($controllerName);
|
|
||||||
// выводим имя контроллера
|
|
||||||
$actionName = 'action' . ucfirst(array_shift($segments));
|
$actionName = 'action' . ucfirst(array_shift($segments));
|
||||||
$controllerFile = __DIR__ . '/../app/controller/' . $controllerName . '.php';
|
$controllerObject = new $controllerName();
|
||||||
var_dump($controllerFile);
|
$result = $controllerObject->$actionName();
|
||||||
if (file_exists($controllerFile)) {
|
// var_dump($controllerFile);
|
||||||
include_once($controllerFile);
|
}
|
||||||
|
|
||||||
|
if (!$controllerName) {
|
||||||
|
// Page not found
|
||||||
|
$obj = new MainController();
|
||||||
|
$obj->actionNotFound();
|
||||||
|
// var_dump($obj);
|
||||||
|
// $controllerName = "MainController";
|
||||||
|
// $actionName = "actionIndex";
|
||||||
|
// $controllerObject = new $controllerName;
|
||||||
|
// $result = $controllerObject::$actionName();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
$controllerObject = new $controllerName;
|
$controllerObject = new $controllerName;
|
||||||
$result = $controllerObject->$actionName();
|
$result = $controllerObject::$actionName();
|
||||||
|
|
||||||
// выводим название экшена
|
// выводим название экшена
|
||||||
echo '<br>' . $result;
|
echo '<br>' . $result;
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once './core/Autoloader.php';
|
// require_once './core/Autoloader.php';
|
||||||
Autoloader::init();
|
// Autoloader::init();
|
||||||
|
|
||||||
// Включение отображения ошибок на время разработки сайта
|
// Включение отображения ошибок на время разработки сайта
|
||||||
ini_set('display_errors', 1);
|
ini_set('display_errors', 1);
|
||||||
|
define('ROOT', dirname(__FILE__));
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
// Подключаем файл Router.php используя следующие команды:
|
// Подключаем файл Router.php используя следующие команды:
|
||||||
define('ROOT', dirname(__FILE__));
|
|
||||||
require_once (ROOT . '/core/Router.php');
|
require_once (ROOT . '/core/Router.php');
|
||||||
|
|
||||||
//проверка: echo ROOT; (C:\OSPanel\domains\test2)
|
//проверка: echo ROOT; (C:\OSPanel\domains\test2)
|
||||||
@ -24,47 +25,47 @@ exit;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
var_dump($_SERVER['REQUEST_URI']);
|
// var_dump($_SERVER['REQUEST_URI']);
|
||||||
$uri = trim($_SERVER['REQUEST_URI'], '/');
|
// $uri = trim($_SERVER['REQUEST_URI'], '/');
|
||||||
|
|
||||||
$mass_uri = explode('/', $uri);
|
// $mass_uri = explode('/', $uri);
|
||||||
var_dump($mass_uri);
|
// var_dump($mass_uri);
|
||||||
|
|
||||||
$controller = $mass_uri[0];
|
// $controller = $mass_uri[0];
|
||||||
$action = $mass_uri[1] ? $mass_uri[1] : 'index';
|
// $action = $mass_uri[1] ? $mass_uri[1] : 'index';
|
||||||
$nameClassController = ucfirst($controller) . 'Controller';
|
// $nameClassController = ucfirst($controller) . 'Controller';
|
||||||
|
|
||||||
$cntr = new $nameClassController;
|
// $cntr = new $nameClassController;
|
||||||
$cntr->$action();
|
// $cntr->$action();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MainModel
|
// class MainModel
|
||||||
{
|
// {
|
||||||
public function getData()
|
// public function getData()
|
||||||
{
|
// {
|
||||||
return [
|
// return [
|
||||||
'title' => 'Main Page',
|
// 'title' => 'Main Page',
|
||||||
'h3' => 'С новым годом!'
|
// 'h3' => 'С новым годом!'
|
||||||
];
|
// ];
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
class MainController
|
// class MainController
|
||||||
{
|
// {
|
||||||
public function index()
|
// public function index()
|
||||||
{
|
// {
|
||||||
$model = new MainModel();
|
// $model = new MainModel();
|
||||||
$view = new MainView();
|
// $view = new MainView();
|
||||||
$result = $model->getData();
|
// $result = $model->getData();
|
||||||
$view->render($result, 'main.tpl');
|
// $view->render($result, 'main.tpl');
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
class MainView
|
// class MainView
|
||||||
{
|
// {
|
||||||
public function render($data, $tmpl)
|
// public function render($data, $tmpl)
|
||||||
{
|
// {
|
||||||
var_dump($data);
|
// var_dump($data);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
$cont = new Route();
|
// $cont = new Route();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/** @type {import('tailwindcss').Config} */
|
/** @type {import('tailwindcss').Config} */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
content: ["./template/*.{html,js}"],
|
content: ["./app/template/*.{html,js,php}"],
|
||||||
theme: {
|
theme: {
|
||||||
extend: {},
|
extend: {},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user