Home page
This commit is contained in:
parent
6250bc5a98
commit
ba715dc577
7 changed files with 64 additions and 35 deletions
31
migrations/Version20210114120206.php
Normal file
31
migrations/Version20210114120206.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20210114120206 extends AbstractMigration
|
||||
{
|
||||
public function getDescription() : string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema) : void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE UNIQUE INDEX UNIQ_5A8A6C8D989D9B62 ON post (slug)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema) : void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('DROP INDEX UNIQ_5A8A6C8D989D9B62 ON post');
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Post;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
@ -15,6 +16,7 @@ class HomeController extends AbstractController
|
|||
{
|
||||
return $this->render('home/index.html.twig', [
|
||||
'controller_name' => 'HomeController',
|
||||
'posts' => $this->getDoctrine()->getRepository(Post::class)->findBy(array(), array('publishedAt' => 'DESC'), 5, 0)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Post;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
@ -9,12 +10,15 @@ use Symfony\Component\Routing\Annotation\Route;
|
|||
class PostController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @Route("/post", name="post")
|
||||
* @Route("/post/{slug}", name="post")
|
||||
* @param string $slug
|
||||
* @return Response
|
||||
*/
|
||||
public function index(): Response
|
||||
public function index(string $slug): Response
|
||||
{
|
||||
return $this->render('post/index.html.twig', [
|
||||
'controller_name' => 'PostController',
|
||||
'post' => $this->getDoctrine()->getRepository(Post::class)->findOneBy(array('slug' => $slug))
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class Post
|
|||
private $content;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255)
|
||||
* @ORM\Column(type="string", length=255, unique=true)
|
||||
*/
|
||||
private $slug;
|
||||
|
||||
|
|
|
@ -6,12 +6,13 @@
|
|||
{% block stylesheets %}
|
||||
{{ encore_entry_link_tags('app') }}
|
||||
{% endblock %}
|
||||
{% set admin = false %} <!-- ToDo: Change this with dynamic -->
|
||||
</head>
|
||||
<body>
|
||||
<!-- Navbar -->
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="#">Blog</a>
|
||||
<a class="navbar-brand" href="{{ path('home') }}m">Blog</a>
|
||||
|
||||
<button
|
||||
class="navbar-toggler"
|
||||
|
@ -27,9 +28,14 @@
|
|||
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||
{% if admin %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" aria-current="page" href="#">Home</a>
|
||||
<a class="nav-link active" aria-current="page" href="{{ path('post') }}">Posts</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" aria-current="page" href="{{ path('category') }}">Categories</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -3,18 +3,17 @@
|
|||
{% block title %}Hello HomeController!{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<style>
|
||||
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
|
||||
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
|
||||
</style>
|
||||
|
||||
<div class="example-wrapper">
|
||||
<h1>Hello {{ controller_name }}! ✅</h1>
|
||||
|
||||
This friendly message is coming from:
|
||||
<ul>
|
||||
<li>Your controller at <code><a href="{{ '/home/flifloo/Nextcloud/IUT/PHP Avancée/blog/src/Controller/HomeController.php'|file_link(0) }}">src/Controller/HomeController.php</a></code></li>
|
||||
<li>Your template at <code><a href="{{ '/home/flifloo/Nextcloud/IUT/PHP Avancée/blog/templates/home/index.html.twig'|file_link(0) }}">templates/home/index.html.twig</a></code></li>
|
||||
</ul>
|
||||
</div>
|
||||
<h1 class="text-center">Last 5 posts</h1>
|
||||
<div class="container-fluid justify-content-center">
|
||||
{% for post in posts %}
|
||||
<div class="card text-center">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">{{ post.title }}</h5>
|
||||
<p class="card-text">{{ post.description }}</p>
|
||||
<a href="{{ path('post', {slug: post.slug}) }}" class="btn btn-primary">Read more</a>
|
||||
</div>
|
||||
<div class="card-footer text-muted">{{ post.publishedAt.format('Y-m-d H:i:s') }}</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -3,18 +3,5 @@
|
|||
{% block title %}Hello PostController!{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<style>
|
||||
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
|
||||
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
|
||||
</style>
|
||||
|
||||
<div class="example-wrapper">
|
||||
<h1>Hello {{ controller_name }}! ✅</h1>
|
||||
|
||||
This friendly message is coming from:
|
||||
<ul>
|
||||
<li>Your controller at <code><a href="{{ '/home/flifloo/Nextcloud/IUT/PHP Avancée/blog/src/Controller/PostController.php'|file_link(0) }}">src/Controller/PostController.php</a></code></li>
|
||||
<li>Your template at <code><a href="{{ '/home/flifloo/Nextcloud/IUT/PHP Avancée/blog/templates/post/index.html.twig'|file_link(0) }}">templates/post/index.html.twig</a></code></li>
|
||||
</ul>
|
||||
</div>
|
||||
{{ dump(post) }}
|
||||
{% endblock %}
|
||||
|
|
Reference in a new issue