I am trying out Symfony the first time. I installed it with
<code>composer create-project symfony/website-skeleton crudapp
</code>
<code>composer create-project symfony/website-skeleton crudapp
</code>
composer create-project symfony/website-skeleton crudapp
I have an Apache config like this:
<code><VirtualHost *:80>
ServerName localhost
DocumentRoot "c:/.../Symfony/crudapp/public/"
<Directory "c:/.../Symfony/crudapp/public/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
</code>
<code><VirtualHost *:80>
ServerName localhost
DocumentRoot "c:/.../Symfony/crudapp/public/"
<Directory "c:/.../Symfony/crudapp/public/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
</code>
<VirtualHost *:80>
ServerName localhost
DocumentRoot "c:/.../Symfony/crudapp/public/"
<Directory "c:/.../Symfony/crudapp/public/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
I got a welcome page for http://localhost
, but when I try to add a new controller e.g.
<code>php bin/console make:controller
-> Main
</code>
<code>php bin/console make:controller
-> Main
</code>
php bin/console make:controller
-> Main
Then the controller is created in the src/Controller
folder, but the route is not used by Symfony.
<code><?php
namespace AppController;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentRoutingAnnotationRoute;
class MainController extends AbstractController
{
#[Route('/main', name: 'app_main')]
public function index(): Response
{
return $this->render('main/index.html.twig', [
'controller_name' => 'MainController',
]);
}
}
</code>
<code><?php
namespace AppController;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentRoutingAnnotationRoute;
class MainController extends AbstractController
{
#[Route('/main', name: 'app_main')]
public function index(): Response
{
return $this->render('main/index.html.twig', [
'controller_name' => 'MainController',
]);
}
}
</code>
<?php
namespace AppController;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentRoutingAnnotationRoute;
class MainController extends AbstractController
{
#[Route('/main', name: 'app_main')]
public function index(): Response
{
return $this->render('main/index.html.twig', [
'controller_name' => 'MainController',
]);
}
}
Or at least I got 404 error when trying to visit the http://localhost/main
.
Any idea how to fix this?