The Blog

Ubuntu 22.04 LTS + Plesk 18 + PHP 8.1 + Symfony 6.1 and so on Posted on

First issue after installing all of that was symfony-cli could not find Plesk’s PHP, this fixed it.

sudo ln -s /opt/plesk/php/8.0/bin/php /usr/local/bin/php

Next issue was “KnpMenuBundle” in 6.1 it needs to be used as a service, see here. Also if you want custom template the path needs to be set this way; if your template is in “templates/Menu/knp_menu.html.twig”

#config/packages/knp_menu.yaml

knp_menu:
    # use 'twig: false' to disable the Twig extension and the TwigRenderer
    twig:
        template: Menu/knp_menu.html.twig
    #  if true, enables the helper for PHP templates
    templating: false
    # the renderer to use, list is also available by default
    default_renderer: twig

Another issue was, how to use raw SQL in symfony 6, very simple thanks to auto-wiring.

https://symfonycasts.com/screencast/doctrine-queries/raw-sql-queries


Few samples of raw SQL for MySQL:

# get connection
$conn = $managerRegistry->getConnection();

# sample 1
$sql = "SELECT * FROM somethingWHERE id = :user_id";
$resultSet = $conn->executeQuery($sql, ['user_id' => 123]);
$results = $resultSet->fetchAllAssociative();

# sample 2
$sql = "SELECT * FROM something";
$result = $conn->fetchAllAssociative($sql);
This entry was posted in Symfony 6, Uncategorized. Bookmark the permalink.

Please Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *



CAPTCHA
Change the CAPTCHA codeSpeak the CAPTCHA code