-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c9adf4
commit 698bd44
Showing
11 changed files
with
349 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<?php | ||
|
||
namespace App\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; | ||
use App\Entity\Blog; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
|
||
class BlogController extends AbstractController | ||
{ | ||
/** | ||
* @Route("/blog", name="blog") | ||
*/ | ||
public function index() | ||
{ | ||
$repository = $this->getDoctrine()->getRepository(Blog::class); | ||
$blogs = $repository->findAll(); | ||
|
||
return $this->render('blog/index.html.twig', [ | ||
'blogs' => $blogs, | ||
]); | ||
} | ||
|
||
/** | ||
* @Route("/create", name="create") | ||
@Method("GET") | ||
*/ | ||
public function create() | ||
{ | ||
return $this->render('create.html.twig'); | ||
} | ||
|
||
/** | ||
* @Route("/submit", name="submit") | ||
@Method("POST") | ||
*/ | ||
public function submit(Request $request) | ||
{ | ||
$blog=new Blog(); | ||
$title=$request->request->get('title'); | ||
$author=$request->request->get('author'); | ||
$date=$request->request->get('date'); | ||
$content=$request->request->get('content'); | ||
|
||
$blog->setTitle($title); | ||
$blog->setAuthor($author); | ||
$blog->setContent($content); | ||
|
||
|
||
|
||
$em=$this->getDoctrine()->getManager(); | ||
$em->persist($blog); | ||
$em->flush(); | ||
|
||
return $this->redirectToRoute('create'); | ||
|
||
} | ||
|
||
/** | ||
* @Route("/show/{id}", name="show") | ||
@Method("GET") | ||
*/ | ||
public function show($id) | ||
{ | ||
$repository = $this->getDoctrine()->getRepository(Blog::class); | ||
$blog = $repository->find($id); | ||
return $this->render('show.html.twig',[ | ||
'blog'=>$blog | ||
]); | ||
} | ||
|
||
/** | ||
* @Route("/edit/{id}", name="edit") | ||
@Method("GET") | ||
*/ | ||
public function edit($id) | ||
{ | ||
$blog = $this->getDoctrine()->getRepository(Blog::class)->find($id); | ||
|
||
return $this->render('edit.html.twig',[ | ||
'blog'=>$blog | ||
]); | ||
} | ||
|
||
/** | ||
* @Route("/edit-submit/{id}", name="edit-submit") | ||
@Method("PUT") | ||
*/ | ||
public function editSubmit(Request $request, $id) | ||
{ | ||
$blog = $this->getDoctrine()->getRepository(Blog::class)->find($id); | ||
$title=$request->request->get('title'); | ||
$author=$request->request->get('author'); | ||
$date=$request->request->get('date'); | ||
$content=$request->request->get('content'); | ||
|
||
$blog->setTitle($title); | ||
$blog->setAuthor($author); | ||
$blog->setContent($content); | ||
|
||
$em=$this->getDoctrine()->getManager(); | ||
|
||
$em->flush(); | ||
|
||
return $this->redirectToRoute('blog'); | ||
} | ||
|
||
/** | ||
* @Route("delete/{id}", name="delete") | ||
* @Method("DELETE") | ||
*/ | ||
public function delete(Request $request, $id) | ||
{ | ||
$blog = $this->getDoctrine()->getRepository(Blog::class)->find($id); | ||
|
||
$em=$this->getDoctrine()->getManager(); | ||
$em->remove($blog); | ||
$em->flush(); | ||
|
||
return $this->redirectToRoute('blog'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?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 Version20190504233047 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->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); | ||
|
||
$this->addSql('CREATE TABLE blogs (id INT AUTO_INCREMENT NOT NULL, title VARCHAR(255) NOT NULL, author VARCHAR(255) NOT NULL, content LONGTEXT NOT NULL, date DATE NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); | ||
} | ||
|
||
public function down(Schema $schema) : void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); | ||
|
||
$this->addSql('DROP TABLE blogs'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{% extends 'base.html.twig' %} | ||
|
||
{% block title %}Hello BlogController!{% 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>All Blogs ✅</h1> | ||
|
||
<table> | ||
<thead> | ||
<tr> | ||
Title | ||
</tr> | ||
<tr> | ||
Author | ||
</tr> | ||
<tr> | ||
Settings | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for blog in blogs %} | ||
<td> | ||
{{blog.title()}} | ||
</td> | ||
<td>{{blog.author}}</td> | ||
<td> | ||
<a href="/show/{{blog.id}}" class="btn btn-primary">Show</a> | ||
<a href="/edit/{{blog.id}}" class="btn btn-info">Edit</a> | ||
<form class="" action="{{path('delete',{ 'id' : blog.id })}}" method="post"> | ||
<input type='hidden' name='_method' value='DELETE'> | ||
<button type="submit" name="button" class="btn btn-danger">Delete</button> | ||
|
||
</td> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
|
||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{% extends 'base.html.twig' %} | ||
|
||
{% block title %}Hello BlogContorllerController!{% endblock %} | ||
|
||
{% block body %} | ||
|
||
|
||
<div class="example-wrapper"> | ||
<h1>Create Blog ✅</h1> | ||
|
||
<form class="" action="{{path('submit')}}" method="post"> | ||
<div class="form-group"> | ||
<label for="name" class="control-label">Title</label> | ||
<input type="text" class="form-control" name="title"> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label for="name" class="control-label">Author</label> | ||
<input type="text" class="form-control" name="author"> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label for="name" class="control-label">Date</label> | ||
<input type="date" class="form-control" name="date"> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label for="name" class="control-label">Content</label> | ||
<textarea name="content" rows="8" class="form-control"></textarea> | ||
</div> | ||
|
||
<button type="submit" name="button">Save</button> | ||
</form> | ||
</div> | ||
{% endblock %} |
Oops, something went wrong.