Implementing Tracy debugging tool

Cupara
Member | 90
+
0
-

I'm having a problem trying to get the panel to display. I know I have errors on the page I'm implementing it on first before I implement on the rest of the pages.

I have the following for my news.php file:

<?php
require_once 'vendor/autoload.php';
require_once 'includes/db.php';

$latte = new Latte\Engine;
$latte->setTempDirectory('temp');
$latte->addExtension(new \Latte\Bridges\Tracy\TracyExtension);

if (isset($_GET['slug'])) {
    // Display individual news entry
    $slug = $_GET['slug'];
    $result = $conn->query("SELECT * FROM news WHERE slug = '$slug'");
    $news = $result->fetch_assoc();
    var_dump($news);
    echo $latte->render(__DIR__.'/templates/news_detail.latte', ['news' => $news]);
} else {
    // Display news listing
    $result = $conn->query('SELECT * FROM news ORDER BY created_at DESC');
    $news = $result->fetch_all(MYSQLI_ASSOC);

    echo $latte->render(__DIR__.'/templates/news.latte', ['news' => $news]);
}

Can anyone please take a look and let me know if they see my mistake or give me the proper way of implementing it? Yes, I have already ran the installation of Tracy via composer.

Thanks

nightfish
Member | 517
+
0
-

@Cupara Do you mean database query panel in Tracy? If so, you need to use a database library that supports it. It could be Nette's own nette/database or dibi/dibi – both have integrations for Tracy (NDB, dibi). You would, however, probably need to add the panel to Tracy manually as it seems you are not using nette/di, which would do it for you.

EDIT: On the other hand if you only mean Tracy debugger in general, then it should be sufficient to enable it.

Last edited by nightfish (2023-12-22 20:57)

Cupara
Member | 90
+
0
-

@nightfish yes I mean the Tracy debugger. I intend to implement more of Nette's modules and expand the site further over the coming days before I launch it middle of next week.

Anyway, I tried enabling it following those instructions, here's my entire file with it there and I know there are errors on this page but I don't understand why it's not working.

<?php
use Tracy\Debugger;

require_once 'vendor/autoload.php';
require_once 'includes/db.php';

Debugger::enable();

$latte = new Latte\Engine;
$latte->setTempDirectory('temp');
$latte->addExtension(new \Latte\Bridges\Tracy\TracyExtension);

if (isset($_GET['slug'])) {
    // Display individual news entry
    $slug = $_GET['slug'];
    $statement = $conn->prepare('SELECT * FROM news WHERE slug = ?');
    $statement->bind_param('s', $slug);
    $statement->execute();
    $result = $statement->get_result();
    $news = $result->fetch_assoc();

    echo $latte->render(__DIR__.'/templates/news_detail.latte', ['news' => $news]);
} else {
    // Display news listing
    $statement = $conn->prepare('SELECT * FROM news ORDER BY created_at DESC');
    $statement->execute();
    $result = $statement->get_result();
    $news = $result->fetch_all(MYSQLI_ASSOC);

    echo $latte->render(__DIR__.'/templates/news.latte', ['news' => $news]);
}

nightfish
Member | 517
+
0
-

@Cupara When you run Tracy::enable() without arguments, it autodetects whether it is running locally and if not, it does not not show Tracy bar. As you are probably trying to run the site on a server, which is not your localhost, Tracy does not show a bar.

You can override the behavior by calling Debugger::enable(Debugger::Development), but that should be only temporary solution to test that it works. Enabling Tracy on a publicly accessible server is a security issue. You can limit Tracy to your IP address or to a combination of IP address and a cookie – see Development vs. production mode for more details.

Cupara
Member | 90
+
0
-

@nightfish No no no no, I know the difference between localhost and my server and I don't have any of my programs open for localhost development, I'm developing it straight on the server. I made sure to run the composer install of Tracy on my server.

I tried overriding the behaviour prior and it didn't work either.

nightfish
Member | 517
+
0
-

@Cupara Okay, let me try, I have probably never used Tracy and Latte separately, so I am not sure if there is some more configuration required.

nightfish
Member | 517
+
0
-

@Cupara I have tried running the following code from my server (see https://hetzner.nufu.eu/…-tracy-test/) and Tracy bar is visible:

index.php

<?php declare(strict_types = 1);

use Tracy\Debugger;

require __DIR__ . '/vendor/autoload.php';

Debugger::enable(Debugger::Development);

$latte = new Latte\Engine;
$latte->setTempDirectory('temp');
$latte->addExtension(new Latte\Bridges\Tracy\TracyExtension);

echo $latte->render(__DIR__.'/test.latte', ['foo' => 'bar']);

test.latte

{block content}
    <h1>Hello Kitty</h1>
    {dump $foo}
{/block}
Cupara
Member | 90
+
0
-

Interesting. Thanks for all your help today @nightfish