Open this website in your browser: http://symfony4.limenius.com/.
The slides for the sections of theory are available at https://www.slideshare.net/nachomartin/symfony-4-workshop-limenius.
What are Symfony 4 and Symfony Flex about.
Let's create a Symfony project with Flex.
Flex is the new way to start projects in Symfony 4. Let's use it to create a new project.
composer create-project symfony/skeleton sf4workshop
cd sf4workshop
Let's write a controller
Fire up your favorite editor and create a new file in src/Controller/DefaultController.php
.
1 2 3 4 5 6 7 8 9 10 11 12 13
<?php namespace App\Controller; use Symfony\Component\HttpFoundation\Response; class DefaultController { public function index() { return new Response('<html><body>Hi there!</body></html>'); } }
Also, uncomment these lines in config/routes.yaml
1 2 3
index: path: / controller: App\Controller\DefaultController::index
config/routes.yml
and not config/packages/routing.yml
. It is easy to make that mistake!Now we are ready to see our first page.
For convenience, we will install the WebServer Bundle, instead of configuring Apache or Nginx.
composer req webserver
Now run:
bin/console server:run
And visit with your browser http://localhost:8000
.
We should see our first page.
If you see an error about permissions, Symfony needs to be able to write into the /var/cache
directory. This is typically fixed after installation when you run bin/console cache:clear