First Project Creation
After installation we should to install .httaccess file
composer require symfony/appache-pack
If you use in local development open Server you should write next configuration.
In file Apache_2.4-PHP_8.0-8.1_vhost.conf or enother that your wor, next text
C:\ospanel\userdata\config\Apache_2.4-PHP_8.0-8.1_vhost.conf <VirtualHost *:80> DocumentRoot "C:\ospanel\domains\sym.loc\public" ServerName "sym.loc" ServerAlias "sym.loc" </VirtualHost>
After if you planing to use annotations you should install them.
composer require annotations
After if you planning to use templates install twig
composer require twig
Custom project
config\routes.yaml
app_lucky_number:
path: /lucky/number
controller: App\Controller\LuckyController:number
controllers:
resource: ../src/Controller/
type: annotation
kernel:
resource: ../src/Kernel.php
type: annotation
src\Controller\CatalogController.php
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class CatalogController extends AbstractController{
#[Route('/blog', name: 'blog_list')]
public function list(): Response
{
return $this->render('my/index.html.twig', array("mydata" => "Timur"));
}
#[Route('/blog2')]
public function list2(): Response
{
return $this->render('my/index.html.twig', array("mydata" => "Timur2"));
}
/*composer require annotations*/
/**
* @Route("/blog3")
*/
public function list3(): Response
{
return $this->render('my/index.html.twig', array("mydata" => "Timur3"));
}
}
src\Controller\LuckyController.php
<?php
namespace App\Controller;
//use http\Env\Response;
use Symfony\Component\HttpFoundation\Response;
class LuckyController{
public function number(){
$number = random_int(0, 2000);
return new Response("Lucky:".$number);
}
}
templates\my\index.html.twig
{# Comment #}
{{ mydata }}
To debug you could use next commands
php bin/console - shows all commands php bin/console debug:router - show all routes php bin/console debug:router --show-controllers --env=ENV - show all controllers php bin/console router:match /blog - show route about information
Install debug panel
composer require --dev profiler