Skip to content
Snippets Groups Projects
Commit dd80058b authored by Адлан Шамавов's avatar Адлан Шамавов
Browse files

add readLogFile

parent 36458228
No related branches found
No related tags found
1 merge request!8Ptps controller 8
...@@ -8,4 +8,6 @@ V ...@@ -8,4 +8,6 @@ V
C C
assets/bootstrap.js,0\3\03141036569b5869397180192f8b98c1360e1556 assets/bootstrap.js,0\3\03141036569b5869397180192f8b98c1360e1556
E E
assets/styles/app.css,5\8\58d82e459ad700473925afc6a4d3ceb1cbdfdf19 assets/styles/app.css,5\8\58d82e459ad700473925afc6a4d3ceb1cbdfdf19
\ No newline at end of file E
public/files/text.txt,9\9\994b95f5d0e2f9641bf4e2c30422e6a0a6a105b5
\ No newline at end of file
...@@ -8,4 +8,6 @@ V ...@@ -8,4 +8,6 @@ V
C C
assets/bootstrap.js,0\3\03141036569b5869397180192f8b98c1360e1556 assets/bootstrap.js,0\3\03141036569b5869397180192f8b98c1360e1556
E E
assets/styles/app.css,5\8\58d82e459ad700473925afc6a4d3ceb1cbdfdf19 assets/styles/app.css,5\8\58d82e459ad700473925afc6a4d3ceb1cbdfdf19
\ No newline at end of file E
public/files/text.txt,9\9\994b95f5d0e2f9641bf4e2c30422e6a0a6a105b5
\ No newline at end of file
Раз, два, три, четыре,
пять, шесть, семь, восемь.
\ No newline at end of file
...@@ -12,14 +12,26 @@ use Symfony\Component\Routing\Attribute\Route; ...@@ -12,14 +12,26 @@ use Symfony\Component\Routing\Attribute\Route;
class HomeController extends AbstractController class HomeController extends AbstractController
{ {
private function diffDays(DateTimeImmutable $dateStart, DateTimeImmutable $dateEnd): int { private function readLogFile(string $fileName): string {
return date_diff($dateStart, $dateEnd)->format("%a") ; $filePath = $this->getParameter('kernel.project_dir') . "/public/files/" . $fileName;
if (file_exists($filePath)) {
$text = "";
$file = fopen($filePath, "r");
while(!feof($file)) {
$line = fgets($file);
$text .= $line;
}
fclose($file);
return $text;
}
return "Такого файла не существует.";
} }
#[Route('/{startDate}/{endDate}', name: 'home')] // 01-01-2024
public function home(string $startDate, string $endDate): Response #[Route('/{fileName}', name: 'home')]
public function home(string $fileName): Response // text.txt
{ {
$countDays = $this->diffDays(new DateTimeImmutable($startDate), new DateTimeImmutable($endDate)); $text = $this->readLogFile($fileName);
return $this->render('home.html.twig', ['count' => $countDays]); return $this->render('home.html.twig', ['text' => $text]);
} }
} }
{% block body %} {% block body %}
<h1>Кол-во дней между датами: {{ count }}</h1> <h1>{{ text }}</h1>
{% endblock %} {% endblock %}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment