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;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Post;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
@ -15,6 +16,7 @@ class HomeController extends AbstractController
|
||||||
{
|
{
|
||||||
return $this->render('home/index.html.twig', [
|
return $this->render('home/index.html.twig', [
|
||||||
'controller_name' => 'HomeController',
|
'controller_name' => 'HomeController',
|
||||||
|
'posts' => $this->getDoctrine()->getRepository(Post::class)->findBy(array(), array('publishedAt' => 'DESC'), 5, 0)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Post;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
@ -9,12 +10,15 @@ use Symfony\Component\Routing\Annotation\Route;
|
||||||
class PostController extends AbstractController
|
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', [
|
return $this->render('post/index.html.twig', [
|
||||||
'controller_name' => 'PostController',
|
'controller_name' => 'PostController',
|
||||||
|
'post' => $this->getDoctrine()->getRepository(Post::class)->findOneBy(array('slug' => $slug))
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ class Post
|
||||||
private $content;
|
private $content;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=255)
|
* @ORM\Column(type="string", length=255, unique=true)
|
||||||
*/
|
*/
|
||||||
private $slug;
|
private $slug;
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,13 @@
|
||||||
{% block stylesheets %}
|
{% block stylesheets %}
|
||||||
{{ encore_entry_link_tags('app') }}
|
{{ encore_entry_link_tags('app') }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
{% set admin = false %} <!-- ToDo: Change this with dynamic -->
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<!-- Navbar -->
|
<!-- Navbar -->
|
||||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<a class="navbar-brand" href="#">Blog</a>
|
<a class="navbar-brand" href="{{ path('home') }}m">Blog</a>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
class="navbar-toggler"
|
class="navbar-toggler"
|
||||||
|
@ -27,9 +28,14 @@
|
||||||
|
|
||||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||||
<li class="nav-item">
|
{% if admin %}
|
||||||
<a class="nav-link active" aria-current="page" href="#">Home</a>
|
<li class="nav-item">
|
||||||
</li>
|
<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>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -3,18 +3,17 @@
|
||||||
{% block title %}Hello HomeController!{% endblock %}
|
{% block title %}Hello HomeController!{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<style>
|
<h1 class="text-center">Last 5 posts</h1>
|
||||||
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
|
<div class="container-fluid justify-content-center">
|
||||||
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
|
{% for post in posts %}
|
||||||
</style>
|
<div class="card text-center">
|
||||||
|
<div class="card-body">
|
||||||
<div class="example-wrapper">
|
<h5 class="card-title">{{ post.title }}</h5>
|
||||||
<h1>Hello {{ controller_name }}! ✅</h1>
|
<p class="card-text">{{ post.description }}</p>
|
||||||
|
<a href="{{ path('post', {slug: post.slug}) }}" class="btn btn-primary">Read more</a>
|
||||||
This friendly message is coming from:
|
</div>
|
||||||
<ul>
|
<div class="card-footer text-muted">{{ post.publishedAt.format('Y-m-d H:i:s') }}</div>
|
||||||
<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>
|
</div>
|
||||||
<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>
|
{% endfor %}
|
||||||
</ul>
|
</div>
|
||||||
</div>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -3,18 +3,5 @@
|
||||||
{% block title %}Hello PostController!{% endblock %}
|
{% block title %}Hello PostController!{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<style>
|
{{ dump(post) }}
|
||||||
.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>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Reference in a new issue