提交 118fe568 编写于 作者: T teebbstudios

post_show() and @ParamConverter

上级 fe299bb8
......@@ -17,6 +17,8 @@ framework:
php_errors:
log: true
ide: phpstorm
assets:
packages:
......
......@@ -5,6 +5,7 @@ namespace App\Controller;
use App\Entity\Post;
use App\Form\PostType;
use App\Repository\PostRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
......@@ -21,8 +22,9 @@ class PostController extends AbstractController
]);
}
#[Route('/post/{id}', name: 'post_show', methods: ['GET'])]
public function show(Post $post): Response
#[Route('/post/{id1}', name: 'post_show', methods: ['GET'])]
#[ParamConverter('post', options: ['id' => 'id1'])]
public function show(Request $request, Post $post): Response
{
return $this->render('post/show.html.twig', [
'post' => $post,
......
......@@ -21,7 +21,7 @@
</tr>
<tr>
<th>Body</th>
<td>{{ post.body }}</td>
<td>{{ post.body|raw }}</td>
</tr>
<tr>
<th>Status</th>
......@@ -37,14 +37,15 @@
</tr>
<tr>
<th>PostImage</th>
<td>{{ post.postImage }}</td>
<td>
{% if post.postImage is not null %}
<img src={{ asset(post.postImage, 'file_upload') }}>
{% endif %}
</td>
</tr>
</tbody>
</table>
<a href="{{ path('post_index') }}">back to list</a>
<a href="{{ path('post_edit', {'id': post.id}) }}">edit</a>
{{ include('post/_delete_form.html.twig') }}
{% endblock %}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册