some homework

This commit is contained in:
Aleksandr Shelkovin 2025-01-19 17:54:54 +03:00
parent 2812b5e9d8
commit 013df07ce2
8 changed files with 96 additions and 37 deletions

View File

@ -7,12 +7,11 @@ class AboutController
public function actionIndex()
{
$result = AboutModel::getData();
var_dump($result);
// var_dump($result);
echo (View::render([
'box' => $result,
'body' => 'To home',
'auth' => false
], 'tpl_layout.php'));
print("AboutController, А кто то почувствовал перерыв?");
}
}

View File

@ -0,0 +1,8 @@
<?php
require_once __DIR__ . "/../view/View.php";
class AdminController {
public function actionIndex() {
echo (View::render([], 'admin.php'));
}
}

View File

@ -7,9 +7,6 @@ class MainController
{
public function actionNotFound()
{
// $result = AboutModel::getData();
// var_dump($result);
echo (View::render([], '404.php'));
// print("AboutController, А кто то почувствовал перерыв?");
}
}

View File

@ -0,0 +1,11 @@
<?php
require_once __DIR__ . "/../model/AboutModule.php";
require_once __DIR__ . "/../view/View.php";
class NewsController
{
public function actionIndex()
{
echo "We have not good news for you!";
}
}

View File

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tailwind Admin Panel</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100">
<div class="flex">
<aside class="bg-gray-800 text-white w-64">
<div class="p-4">
<h2 class="text-xl font-bold">Admin Panel</h2>
</div>
<ul class="p-4">
<li class="mb-2"><a href="#" class="block px-4 py-2 hover:bg-gray-700">Dashboard</a></li>
<li class="mb-2"><a href="#" class="block px-4 py-2 hover:bg-gray-700">Users</a></li>
<li class="mb-2"><a href="#" class="block px-4 py-2 hover:bg-gray-700">Products</a></li>
<li class="mb-2"><a href="#" class="block px-4 py-2 hover:bg-gray-700">Settings</a></li>
</ul>
<div class="p-4 mt-auto">
<button id="logoutButton" class="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">
Logout
</button>
</div>
</aside>
<main class="flex-grow p-4">
<h1 class="text-3xl font-bold mb-4">Dashboard</h1>
<p>Welcome to the admin panel!</p>
</main>
</div>
<script>
document.getElementById('logoutButton').addEventListener('click', function() {
window.location.href = '/'; // Redirect to the home page
});
</script>
</body>
</html>

View File

@ -1,29 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo $body; ?> </title>
<title><?php echo $pageTitle; ?></title>
<style>
body { font-family: sans-serif; }
.audio-player { margin-bottom: 10px; }
.logout, .login { margin-bottom: 10px; }
</style>
</head>
<body>
<?php echo $title; ?>
<?php if ($auth): ?>
<div class="logout"><a href="logout.php">exit</a></div>
<div class="logout"><a href="logout.php">Выход</a></div>
<?php else: ?>
<div class="login"><a href="login.php">login</a></div>
<div class="login"><a href="login.php">Вход</a></div>
<?php endif; ?>
<?php foreach ($box as $item): ?>
<?php
$audioFiles = $box; // Переименовали переменную для ясности
foreach ($audioFiles as $file):
if (file_exists($file)) : ?>
<div class="audio-player">
<audio controls="controls">
<source src="<?php echo $item ?>" type="audio/mpeg">
<source src="<?php echo htmlspecialchars($file); ?>" type="audio/mpeg">
Ваш браузер не поддерживает HTML5 audio.
</audio>
<?php endforeach; ?>
</div>
<?php else: ?>
<p>Файл "<?php echo htmlspecialchars($file); ?>" не найден.</p>
<?php endif;
endforeach;
?>
</body>
</html>

View File

@ -29,6 +29,7 @@ class Router
$actionName = 'action' . ucfirst(array_shift($segments));
$controllerObject = new $controllerName();
$result = $controllerObject->$actionName();
break;
// var_dump($controllerFile);
}
@ -36,19 +37,8 @@ class Router
// Page not found
$obj = new MainController();
$obj->actionNotFound();
// var_dump($obj);
// $controllerName = "MainController";
// $actionName = "actionIndex";
// $controllerObject = new $controllerName;
// $result = $controllerObject::$actionName();
break;
// break;
}
$controllerObject = new $controllerName;
$result = $controllerObject::$actionName();
// выводим название экшена
echo '<br>' . $result;
}
}

View File

@ -4,6 +4,7 @@ return array(
'news' => 'news/index', // actionIndex в NewsController
'products' => 'product/list', // actionList в ProductController
'about' => 'about/index',
'admin' => 'admin/index',
);
// - где 'news' - строка запроса
// 'news/index' - имя контроллера и экшена для обработки этого запроса (путь обработчика)