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
C
assets/bootstrap.js,0\3\03141036569b5869397180192f8b98c1360e1556
E
assets/styles/app.css,5\8\58d82e459ad700473925afc6a4d3ceb1cbdfdf19
\ No newline at end of file
assets/styles/app.css,5\8\58d82e459ad700473925afc6a4d3ceb1cbdfdf19
E
public/files/text.txt,9\9\994b95f5d0e2f9641bf4e2c30422e6a0a6a105b5
\ No newline at end of file
......@@ -8,4 +8,6 @@ V
C
assets/bootstrap.js,0\3\03141036569b5869397180192f8b98c1360e1556
E
assets/styles/app.css,5\8\58d82e459ad700473925afc6a4d3ceb1cbdfdf19
\ No newline at end of file
assets/styles/app.css,5\8\58d82e459ad700473925afc6a4d3ceb1cbdfdf19
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;
class HomeController extends AbstractController
{
private function diffDays(DateTimeImmutable $dateStart, DateTimeImmutable $dateEnd): int {
return date_diff($dateStart, $dateEnd)->format("%a") ;
private function readLogFile(string $fileName): string {
$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));
return $this->render('home.html.twig', ['count' => $countDays]);
$text = $this->readLogFile($fileName);
return $this->render('home.html.twig', ['text' => $text]);
}
}
{% block body %}
<h1>Кол-во дней между датами: {{ count }}</h1>
<h1>{{ text }}</h1>
{% 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