2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Symfonyの構造 Profiler: Your Debugging Best Friend

Posted at

デバッグのためのツールをインストールします。

profilerのインストール

composer require profiler --dev

devコマンドは本番環境に必要ない場合につけます。

これで、フッダーの部分に、デバックバーが表示されるようになります。

dump()を使ってみる

ページ上部にデバッグ情報の表示がされるようになります。

src/Controller/QuestionController.php
<?php

namespace App\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class QuestionController extends AbstractController
{

    /**
     * @Route("/")
     */
    public function homepage()
    {
        return new Response('Hello World');
    }

    /**
     * @Route("/question/{slug}")
     */
    public function show($slug)
    {

        // デバッグのための関数
        dump($slug, $this);

        $answers = [
            'Make sure your cat is sitting purrrfectly still 🤣',
            'Honestly, I like furry shoes better than MY cat',
            'Maybe... try saying the spell backwards?',
        ];

        return $this->render('question/show.html.twig', [
            'question' => ucwords(str_replace('-', ' ', $slug)),
            'answers' => $answers,
        ]);
    }
}

参考

Profiler: Your Debugging Best Friend > Charming Development in Symfony 5 | SymfonyCasts

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?