gstreamer0.10-ffmpeg
gstreamer0.10-plugins-good
packages.
Bienvenido. Hola. Hola, mi nombre es Ryan y tengo el absoluto placer de presentarte el hermoso y fascinante y productivo mundo de Symfony 6. En serio, me siento como Willie Wonka invitándote a mi fábrica de chocolate, excepto que, con suerte, con menos lesiones relacionadas con el azúcar. De todos modos, si eres nuevo en Symfony, estoy... ¡sinceramente un poco celoso! Te va a encantar el viaje... y espero que te conviertas en un desarrollador aún mejor por el camino: definitivamente vas a construir cosas geniales.
La salsa secreta de Symfony es que empieza siendo diminuto, lo que hace que sea fácil de aprender. Pero luego, amplía sus características automáticamente a través de un sistema de recetas único. En Symfony 6, esas características incluyen nuevas herramientas de JavaScript y un nuevo sistema de seguridad... sólo por nombrar dos de las muchas cosas nuevas.
Symfony también es rápido como un rayo, con un gran enfoque en la creación de una experiencia alegre para el desarrollador, pero sin sacrificar las mejores prácticas de programación. Sí: consigues amar la codificación y amar tu código. Lo sé... ha sonado cursi, pero es cierto.
Así que ven conmigo y estarás en un mundo de pura elucidación.
Es la primera vez que canto en estos tutoriales... y quizá la última. Empecemos.
Dirígete a https://symfony.com/download. En esta página, encontrarás algunas instrucciones -que variarán en función de tu sistema operativo- sobre cómo descargar algo llamado el binario de Symfony.
Esto... no es realmente Symfony. Es sólo una herramienta de línea de comandos que nos ayudará a iniciar nuevos proyectos Symfony y nos dará algunas buenas herramientas de desarrollo local. Es opcional, pero lo recomiendo encarecidamente
Una vez que hayas instalado esto - yo ya lo he hecho - abre tu aplicación de terminal favorita. Yo estoy usando iTerm para mac, pero no importa. Si lo has configurado todo correctamente, deberías poder ejecutarlo:
symfony
O incluso mejor
symfony list
para ver una lista de todas las "cosas" que puede hacer este binario de symfony. Hay muchas cosas aquí: cosas que ayudan al desarrollo "local"... y también algunos servicios opcionales para el despliegue. Vamos a repasar las cosas que necesitas saber a lo largo del camino.
Bien, queremos iniciar una nueva y brillante aplicación Symfony. Para ello, ejecuta:
symfony new mixed_vinyl
Donde "mixed_vinyl" es el directorio en el que se descargará la nueva app. Se trata de nuestro proyecto secreto para combinar la mejor parte de los años 90 -no, no el Internet de acceso telefónico, hablo de las cintas de mezcla- con el deleite auditivo de los discos. Más adelante hablaremos de ello.
Entre bastidores, este comando utiliza Composer -el gestor de paquetes de PHP- para crear el nuevo proyecto. Más adelante hablaremos de ello.
El resultado final es que podemos pasar a nuestro nuevo directorio mixed_vinyl
. Abre esta carpeta en tu editor favorito. Yo estoy usando PhpStorm y lo recomiendo encarecidamente.
Conociendo nuestro nuevo Proyecto
¿Qué ha hecho ese comando symfony new
? Ha arrancado un nuevo proyecto Symfony! Ooh. Y ya tenemos un repositorio git. Ejecuta:
git status
Sí: en la rama principal, nada que confirmar. Prueba:
git log
Genial. Después de descargar el nuevo proyecto, el comando confirmó todos los archivos originales automáticamente... lo cual fue muy agradable. Aunque me gustaría que el primer mensaje de confirmación fuera un poco más rockero.
¡Lo que realmente quiero mostrarte es que nuestro nuevo proyecto es súper pequeño! Prueba este comando:
git show --name-only
¡Sí! Todo nuestro proyecto es... unos 17 archivos. Y aprenderemos sobre todos ellos a lo largo del camino. Pero quiero que te sientas cómodo: no hay mucho código aquí.
Vamos a añadir funciones poco a poco. Pero si quieres empezar con un proyecto más grande y con más funciones, puedes hacerlo ejecutando el comando symfony new
con --webapp
.
Tip
Si quieres una nueva aplicación Symfony con todas las funciones, echa un vistazo a https://github.com/dunglas/symfony-docker
Antes de saltar a la codificación, vamos a asegurarnos de que nuestro sistema está listo. Ejecuta otro comando del binario de symfony:
symfony check:req
¡Parece que está bien! Si a tu instalación de PHP le falta alguna extensión... o hay algún otro problema... como que tu ordenador es en realidad una tetera, esto te lo hará saber.
Entonces: tenemos una nueva aplicación Symfony aquí... ¡y nuestro sistema está listo! Todo lo que necesitamos ahora es un subwoofer. Es decir, ¡un servidor web! Puedes configurar un servidor web real como Nginx o algo moderno como Caddy. Pero para el desarrollo local, el binario de Symfony puede ayudarnos. Corre:
symfony serve -d
Y... ¡tenemos un servidor web funcionando! ¡Vuelve!
La primera vez que ejecutes esto, es posible que te pida que ejecutes otro comando para configurar un certificado SSL, lo cual está bien porque entonces el servidor soporta https.
¡Momento de la verdad! Copia la URL, gira hacia tu navegador, aguanta la respiración y ¡woo! Hola página de bienvenida de Symfony 6... completa con extravagantes cambios de color cada vez que recargamos.
A continuación: conozcamos -y hagámonos amigos- del código dentro de nuestra aplicación, para poder desmitificar lo que hace cada parte. Luego codificaremos.
Is there any way to get symfony serve to listen on an address other than localhost? I have symfony set up in a VM, and would like to connect from Firefox running on a physical PC. If not, an ssh tunnel works as a work-around.
Hey Kevin,
I'm not sure it's possible, probably you need to set up a real web server for this, Symfony binary usually is used for local development. Though, I think you need to think about somehow to open that port to your VM so you could run the Sf binary there but connect to it from your local machine (outside of VM). I think it should be possible, maybe try to google some info on the internet.
Cheers!
Hi, I want to install the Symfony CLI on Windows 10 but would like to avoid installing Scoop and use the downloadable binaries instead. However if I execute the symfony.exe file I get the alert that I need to download an app for this task and whether I would like to search for that app in the App Store. After confirming that nothing happens.
What am I doing wrong or how do I go about installing Symfony without Scoop?
Hey Robert J.
My first suggestion is to user Windows WSL 2. It's an embedded Linux environment which works pretty well (that's what I use actually)
If you don't want to change to WSL, I found this SO answer which may help you out: https://stackoverflow.com/a...
I hope it helps. Cheers!
Thanks MolloKhan, yes WSL is also a good solution. I tried it and it works well. What I wanted to achieve though was to install the Symfony CLI natively on Windows but without installing Scoop first. The stackoverflow-link you posted however suggests using Scoop for the installation. But with WSL it works fine and I'm OK with that. Thanks again.
how fix the url character encoding? in the browser the url appears "https:\/\/symfonycast.s3.amazonaws.com\/sample.mp3"
Hello guys.
I have always started a Symfony project, since version 3, as you describe in your tutorial. However, this time I would like to do a full-dockerize SF app but I don't have clear the steps to do that. I was reading https://symfony.com/doc/cur... but it's not very clear for me how to start the project. Please, can you explain me the steps in a general level of what to do? Specially because now Symfony creates some docker files and put this https://github.com/dunglas/... in the tip.
I hope you can help me.
Cesar
Hey Cesar!
Sorry for VERY slow reply - we're usually much faster, but i'm prepping for conference week next week!
To get the full Docker setup, I believe what you need to do is:
git clone git@github.com:dunglas/symfony-docker.git my_new_project
cd my_new_project
rm -rf .git
Then run the commands you see here: https://github.com/dunglas/symfony-docker#getting-started - this will actually create a brand new Symfony project for you run inside that directory, but everything is running entirely from Docker.
So, the basic idea is:
A) To go "full docker" use https://github.com/dunglas/symfony-docker
B) Regardless of whether you go "full docker" or only "part Docker", as you install new packages, if that package contains Docker config, it will be added to your project. This config works with both the full or part Docker setup.
Let me know if this helped :).
Cheers!
Thank you Ryan for answering.
I have followed your instructions and I could star the new project 100% with docker. But, at the end, I have two issues:
1. I am not able to use Composer inside the new project (an error appeared but I don't have problems with Composer in my computer for other projects).
2. I lost the dev tool bar in localhost (and I can not use the symfony server inside the new project)
Probably I am doing something wrong. Is there any way you can add a video showing this process?
Cheers!
Yo Cesar!
- I am not able to use Composer inside the new project (an error appeared but I don't have problems with Composer in my computer for other projects).
Interesting. Are you running composer from your local machine or inside of the container? In the full Docker setup, everything is meant to be run from inside of a container. So, it would be docker-compose exec php composer install
But let me know. Also, if you are running it inside the container, what is the error?
That's true that you can't use the symfony server inside the new project. Or, better-said: there is no reason to use it, because the full-docker setup includes a container that has a web server. So, a web server is already running.
About the dev toolbar, I'm not sure why this wouldn't show up. If you can load the site, the toolbar loads via an Ajax request back to the same server. Do you get an error? Or does it just not show up? Is it possible it's just because the debug bar isn't installed into your app yet? I was able to get it to load after installing it with docker-compose exec php composer require debug
.
Is there any way you can add a video showing this process?
This is a nice idea - but we won't have time too soon for it :).
Cheers!
Hi, Thanks for a new Symfony course. I've been following since Sf4. However, this time I got a new machine and have this problem right from the start...
I installed the symfony-cli (Ubuntu) but it cannot find the binary.
When I try to use the symfony command it says it cannot find it <b>-bash: /usr/local/bin/symfony: No such file or directory</b>
I've also tried apt remove with the --purge option and then reinstalling the cli
If you have any hints, thanks in advance.
Here is a log of my terminal:
`$ sudo apt install symfony-cli
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
symfony-cli
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 5866 kB of archives.
After this operation, 14.5 MB of additional disk space will be used.
Get:1 https://repo.symfony.com/apt symfony-cli 5.4.8 [5866 kB]
Fetched 5866 kB in 2s (2761 kB/s)
Selecting previously unselected package symfony-cli.
(Reading database ... 62284 files and directories currently installed.)
Preparing to unpack .../symfony-cli_5.4.8_amd64.deb ...
Unpacking symfony-cli (5.4.8) ...
Setting up symfony-cli (5.4.8) ...
$ <b>symfony list
-bash: /usr/local/bin/symfony: No such file or directory</b>
$ php -v
PHP 8.1.6 (cli) (built: May 17 2022 16:48:09) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.6, Copyright (c) Zend Technologies
with Zend OPcache v8.1.6, Copyright (c), by Zend Technologies
$ composer -V
Composer version 2.3.5 2022-04-13 16:43:00`
Solved it. If anyone finds the same issue, this is what I had to do.
/etc/environment
file BEFORE the /usr/local/bin/
and logout and login to terminal again.composer self-update --1
but still had some dependency error: symfony/flex[v2.0.0, ..., v2.1.8] require composer-plugin-api ^2.1
sudo update-alternatives --config php
After this all went fine.
Hi, thanks for your cheerful attitude and the content of your tutorials.
I've got a problem: I can't understand while I strictly followed your coding, I still get Symfony 5.4.* on screen.
And when I run : symfony new my_project --version="6.0", I can see an error that has something to interfer with the php context.
So I force upgrade via brew to PHP 8.0* and I still get the same trouble.
Hey Richard, thanks for your kind words :)
Did you download the code from this page? it should get you Symfony 6
What PHP version are you running on? execute php -v
. I'm asking because Symfony 6 requires PHP ^8.0.2 to work, so, if you are on a lower PHP version, the Symfony CLI will detect it and give you an older Symfony version
Cheers!
Did you download the code from this page?
Sorry, I do not know where I could download the code from this page.
With MAM pro I set the php version to 8.0.8 for the folder where I want to create the project.
But if I use the terminal in the folder it say php -v 7.4.29.
I'm sure that it'is the node of the problem. But I don't know how to set php to 8.0.8 or later, for all users.
I've forced an upgrade to php 8 with brew but I can't get out of the issue.
Thanks for attention, maybe you'll find a way.
Anyway, it's not so bad to get stuck to Symfony 5.
HI,
I put the command "symfony new myproject" but when I run my local web with symfony serve -d ... the main page is under Symfony 5.4.7 ... Why?
Hey Francisco C.
That's odd. I just gave it a try and it installed Symfony 6 on my machine. Try upgrading your Symfony CLI
Cheers!
Hey I have Symfony CLI version v4.28.1 (c) 2017-2022 Symfony SAS ... but the problem continous
That may be the problem. I'm on Symfony CLI 5.4.5 and it works as expected - Try upgrading it and give it another try. If that doesn't work, perhaps reinstalling the CLI will do the trick
I'm new to Symfony. Do you think it would be better to watch Symfony 5 tutorials? Is there a big difference between 5 and 6 versions?
Hey H3ck,
Welcome to SymfonyCasts! If you're going to start from scratch - I'd recommend you to follow the new Symfony 6 track unless you already have a project that is based in the previous Symfony 5 version and you have to maintain it - it would be better to follow the version you have then.
The only problem is that Symfony 6 is very fresh and so we don't have too much screencasts about it, though we're actively working on recording new Symfony 6 related courses lately, so more screencasts will come soon! So, it depends on your learning speed, so if you would watch everything we have for Symfony 6 - I'd recommend you to switch to Symfony 5 then - nothing much was changed in Symfony 6 since Symfony 5, so you should follow our Symfony 5 tutorials using Symfony 6 without many issues. But if you got stuck somewhere - feel free to ask questions in the comments below the video mentioning your Symfony version and we will definitely try to help you so you could continue following the course!
So, in short, if you're going to start a new project - I'd recommend you to start it with Symfony 6 nowadays.
Cheers!
Hey H3ck,
You're welcome! If you ever have any problems following SymfonyCasts tutorials - feel free to let us know in the comments below the video, we will help!
Cheers!
Well, I faced a problem. When I tried to pay for a Symfony 5 tutorial it said "Your card was declined". I suppose it has something to do with Russia-Ukraine war (I'm from Russia). But I'm really not supporting it. It's not fair. I'm just a regular guy who wants to program and improve my skills. I even can't link my card to PayPal. Can you please help me somehow, Виктор?
Hey H3ck,
We're sorry to hear that you're experiencing issues with purchasing our products. Please, let us know your email address registered on SymfonyCasts via our contact form: https://symfonycasts.com/co... - we will take a closer look at the reason why the payment card might be declined.
Cheers!
So excited for this to be done already :P
After going through the last course, and bits and pieces of many others on the site, I need to know, if I break away my business logic into their own classes, should I be passing the services and repos etc to them or should I be extending AbstractController for everything to have access to it all ?
Hey David,
We will definitely talk about this further in the upcoming chapters. You don't have to extend that AbstractController, but it has some good shortcuts that you can leverage, just take a look at that class to see them. So, it's up to you to use it or no. What about splitting your business logic into separate services to move it out of the controller - that's a great idea, and it will help you with testing that code, so it definitely worth it. About how to get access to them in the controller? Good question! The best practice would be to inject them into methods (see method injection). In case you have some services that you're using in *every* method of the controller - you can use "constructor injection" instead to unload the signature of your actions. In case you have a lot of services that you have to inject into the controller - take a look at "service subscriber" that will help you to declare the services you should have access to in the controller.
I hope this helps for now! But stay tune, all this will be covered later in this course ;)
Cheers!
// composer.json
{
"require": {
"php": ">=8.0.2",
"ext-ctype": "*",
"ext-iconv": "*",
"symfony/asset": "6.0.*", // v6.0.3
"symfony/console": "6.0.*", // v6.0.3
"symfony/dotenv": "6.0.*", // v6.0.3
"symfony/flex": "^2", // v2.1.5
"symfony/framework-bundle": "6.0.*", // v6.0.4
"symfony/monolog-bundle": "^3.0", // v3.7.1
"symfony/runtime": "6.0.*", // v6.0.3
"symfony/twig-bundle": "6.0.*", // v6.0.3
"symfony/ux-turbo": "^2.0", // v2.0.1
"symfony/webpack-encore-bundle": "^1.13", // v1.13.2
"symfony/yaml": "6.0.*", // v6.0.3
"twig/extra-bundle": "^2.12|^3.0", // v3.3.8
"twig/twig": "^2.12|^3.0" // v3.3.8
},
"require-dev": {
"symfony/debug-bundle": "6.0.*", // v6.0.3
"symfony/stopwatch": "6.0.*", // v6.0.3
"symfony/web-profiler-bundle": "6.0.*" // v6.0.3
}
}
Thank you for this tutorial and all the content !
Merci beaucoup pour ce travail et toutes ces informations !
Vincent