hello everyone and welcome to learn
Symphony for the fourth course for
beginners this video will take you this
four course will take you to how you can
install Symphony and use it we're gonna
explain the different components that
makes them carry a framework and how
they interact with each cue with each
other first let's start by explaining
what's a framework and why you should
use one a framework is basically a
jealous just a set of tools that help
you start making an app in a very quick
way and without having to deal with
every single detail yourself an example
will be security if you don't use a
framework you will have to make sure
that you prevent the smallest risk while
writing the necessary code and
understanding the everyday understanding
the different aspects of that risk but
without a framework but with a framework
most of the basics you know the basic
and well-known threads will be handed
out of the box which lets you let you
focus on the actual stuff that matters
which is writing the actual application
code and logic for your application and
you don't have to reinvent the wheel and
you can use many of the application that
does with many of the tools that really
does something without you know the need
to write it yourself now symphony is a
framework but what should I use simply
now Symphony is a PHP framework that is
made in my intent by since your lives
it's been around for more than a decade
and it's been used by many large
organizations and companies and they
still do to this date now why you should
use Symphony is up to you but here are
some things that I love about Symphony
now the first thing which is the most
important thing for me is the community
that's the most lovable thing about open
source in the symphony community it just
extremely huge and full of helpful
people that would help not not just
understand the concepts but sometimes
even aid you with your own applications
new of your own code
Symphony has a slot workspace where you
can join and ask other ask or answer
questions this the Corps Symphony
developers could be found sometimes
hanging around there in case you wanted
to ask them something specific about the
framework or even discuss some some
patterns or some code the community
itself is extremely up for this
second thing which is the thing that I
fear the most about open source is no
longer maintained and abandoned packages
I hate when I start using some tool or a
framework and and the developers just
decide to move on with their lives and
ask no one to take care of that or
maintain that package anymore but it's
not that's not the case with Symphony
it's maintained extensively and gets up
to updated frequently and you can even
have a have a glimpse or what's coming
coming out by going through some of the
pull requests on github now if you don't
know what github is or a pull request is
that's another symphony thing you don't
have to worry about that the third thing
that I love about which is something
specification 24 it has some people used
to say that before symphony was used for
large applications and not you can not
use it for like small applications or
even medium application that's not the
case anymore taxes infinite for which is
just a small framework like like a layer
though you know you don't have bundles
or modules or whatever big framers
called them but you can have them if you
want to but symphony fall comes out as a
mini framework so you can install it
it's it works for small to medium sized
frameworks and you can even make it for
loud applications can even even have it
for large large applications now let me
just point you to the slack thing that I
was talking about this is the slack if
you go to this internal comm if you
click on this black icon at the bottom
you're gonna get you're gonna be taking
two decent
work space on the swag and you can just
join create your account showing them
and you can ask questions or answer
questions or whatever you want to do or
you texture now enough chitchat let's
get to some symphony stuff now the first
thing before we get started we're gonna
need some stuff we're gonna need so in
order to use a web application we need a
couple of stuff so symphony is a PHP
form up so obviously we're gonna meet
the HP we're gonna need an Apache web
server a web server I'm gonna use Apache
I'm again you can use nginx if you want
to we're gonna need a database system
we're going to use my sequel in this
case and we're going to need composer
which is just something to help us
install bennet packages and even OnStar
Symphony Symphony itself and we're gonna
need a text editor or iid I'm gonna use
the
based on because that's my favorite
editor so let's go ahead and get started
with installing some stuff now the basic
thing which is PHP and a web server in
database could be installed at once by
using lamp stack now just go to
including this I'm gonna go to Google
I'm gonna I'm gonna talk about now I'm
using Ubuntu so I'm gonna download the
correct version for me so this here's
what I understood is called this bit
miami.com
I'm gonna click on that link and right
away it's gonna take me to this page
right here as you can see our windows
mac minutes is gonna amount this page
and i'm just gonna click download for
limit 64 bits bytes and then no thanks
64 bit not bytes and I'm gonna save the
file it's gonna download that but you
can see I already downloaded this and I
found this just to save some time now
after you until you download that what
you want to do is it's not gonna work it
just double-click on it so what you have
to do is you have to component terminal
terminal could be found I'm using 0.2 18
so I can either click on this icon right
here show applications and just start
typing you know type here and as you can
see I have three terminal and start I
have the regular channel which comes
built in with the Ubuntu I have
Tillich's which which is my favorite and
that's what I use and I have extreme so
I'm gonna use Tillich's which is what I
usually use I'm gonna click on that and
I'm using the fish bash just in case you
don't hit the same and I have something
different but everything should be the
same now the first thing you're gonna
notice is we installed that so let's
open our browser for the browser and I'm
gonna get to our downloads and that's
what I have my file as you can see right
here this is the file that I installed
way that I just downloaded which I want
to install now what you want to do is
you want to change the directory to that
part to that folder but what we're gonna
do is if you if you type PWD it's gonna
give you the current directory that you
are in this is harm and this is my
username my tech Ellis is gonna give me
a list of all the all the folders that I
have or the files that I have in this
directory and
you're gonna notice that I have the
Downloads folder which is what I trying
to get so what we're gonna do is we're
going to do CD downloads and now I'm
inside the downloads folder right like
LS you're gonna see that I'm gonna get
my card which is this one right here now
usually it's not gonna be in green I did
I ran a command previously before before
recording the video so you're not gonna
get the same color as this now what you
have to do is type smart plastics and
the name of that run a profile after
that you can click enter you're not
gonna get any feedback where or whatever
but if you talk to this again this
should be green like this you should get
the same user now to run this you have
to type dot slash and the name of that
big mammal um slack now if you just like
the first two or three letters and I hit
tab it's gonna order complete this for
you and you can just you know move on
with your life and just hit enter few
seconds later you can exceed this set of
window you just have to click next and
you can uncheck some of the stuff that
you don't need like just kind of leave
something there right there I don't even
know what that does but I'm gonna leave
it right there I'm gonna eat next and by
default so I can install for me it's
gonna give me an error but I'm gonna eat
next as you can see it's gonna say the
folder is not empty this is not gonna be
the case for you if you don't have this
installed so what you're gonna get max
is just two inputs asking for the
password to the database I just entered
six zeros and this just clicked
installed and it's kind of installed and
that's it you don't have to do anything
else now after you're done you are done
installing this you can I get something
like this window right here which is the
B manager for your for your lamps well
you can see we have three options we
have go to application I'm gonna hit
that and it's gonna open this folder at
this address localhost 8080 now you are
not gonna get the same thing as me
you're gonna get a welcome message from
the Vietnam e application and that's
that's not the case for me
I removed all the file alcohols that I
have right there just so I can you know
move on faster and all that so you gotta
getta with the message and that is going
to confirm that the web server is
working if you don't get that then you
have something wrong and the web server
for you is not work the second thing
that you're going to see is we have open
PHP my admin now PHP my admin is what we
use to manage our database as you can
see right away it's gonna ask me it's
got a greet you - welcome welcome to PHP
myadmin
and you're gonna see we have a username
and a password now the username is just
gonna be route by default the password
is whatever you entered when you were
installing the application the two
inputs that we just you know filled when
we were installing the mam style by
default I entered six zeros so that's
what I'm gonna enter right now I'm gonna
enter a big chunky as you can see I'm in
the dashboard I have my databases right
here as you can see I just installed
this I don't have any other databases
right away so we're gonna create all
around when we get to that part now the
last thing so let me just see what else
we have here
we have open application folder now when
you click this you're gonna go to the
lamp stack directory where it's
installed by default it's installed in
the home directory for me and you're
gonna see that we have a bunch of
folders that we don't need to worry
about now the main thing that I want to
point out is inside the apache2 htdocs
this away your applications will be will
be now by default when you open this
folder you're going to see a bunch of
files those are the files that I was
talking about when you open up when you
click up we'll go to application you're
gonna get a greeting message that
greeting message is loaded from this
place that I just showed you right here
so I just removed everything and we're
gonna get started right away
actually we are not gonna start right
where we need to we still need to
install some stuff now we need to
install PHP this year library now we
install PHP when when we installed the
lamp start now this is great and it's
gonna run PHP and everything but we need
HP to be accessed from the command line
and command line is just to be accessed
from the terminal because we're gonna
use determinar to install some stuff and
as I said we gonna use composer now what
we gonna do without any
say moist in there chitchat let's go
ahead and search for something so I'm
just gonna close this and this one
window and I'm gonna go to Google and
I'm just gonna type open to install PHP
so let's go to HP's 7.2 okay so let's go
and just let's just take whatever length
you find so smooth
see so this is going to install Apache
we don't have to worry about that
because we did that already
unless we want to you want to actually
fetch it from the command line again you
have to fill that stuff now what I'm
interested in is this part right here so
installing PHP 7.2 now what you have to
do is just take these commands and
install them as you can see this is
going to install the HP 7.2 and it's
going to install the command line
interface and is going to install some
stuff with that after that what I want
to do is I want to install some commonly
used PHP extensions and those extensions
are used by composer and by PHP bite the
symphony installer and a lot of stuff
other stuff so what we have to do is
just conspire those now what I'm gonna
do is I'm just gonna take this and I'm
gonna copy this and I'm gonna go back to
my terminal I'm gonna hit shift insert
to paste because there's no command
there's no control V I'm gonna enter
yeah I'm gonna enter my password I'm
gonna hit enter and as you can see it's
gonna do some stuff it's gonna install
some stuff for me so I'm just gonna do Y
which is yes I'm gonna enter
and if you get a dialog like this just
enter and it's gonna continue working
and as you can see it is done now let's
go ahead and try something if you don't
BHP like this if you want to make sure
that the HP is installed you can do HP
garage that version and it's gonna give
you the version of PHP that is installed
which is 7.2 117 now that is great let's
go ahead and do the second most
important thing which is this one now
it's not the most important thing but
it's important so let's go ahead and
copy this one and let's paste it right
below that I'm gonna hit enter and as
you can see nothing always been spotless
it was upgraded because I already
installed everything
so as you can see I have everything
right here but you're gonna get it's
gonna install for you're gonna get some
messages like this like getting some
stuff but it's kind of work for you the
same way now we have that installed now
what we have to do to do next is install
composer now usually what I do is just
go to Google and I'm gonna do install
composer
and I'm just gonna choose whatever link
so I'm gonna choose the first one
because I know it's works that way
because I already made this like many
times ago yeah and as you can see you
can read through that if you want to but
what I'm gonna do is I'm just gonna go
ahead and install some stuff now the
first thing you want to do is you want
to update your packages now we already
did that before we install the HP
obviously right here but you can just go
ahead and did it do it again it's not
gonna hurt anyone next what you have to
do is you have to unstart the curl
utility we call utility is what we're
gonna use to get the actual file the
actual installer as you can see right
here the next thing which is diva now I
already have that I'm not gonna run this
but if you want to just copy it's not
gonna do anything in my case just gonna
tell me that it's already installed but
you can just go ahead and I'm sorry you
don't have that now the next thing which
is the most important thing is to
download this now we're gonna copy this
command we're gonna paste it
it's done the last thing which is the
most important thing we have to do is we
have to copy this command which is gonna
make composure accessible globally for
us from anywhere on our system so we
gonna just copy that command we gonna it
are we gonna paste it we're gonna hit to
Eternity and it gave something so if you
go ahead and try to let's clear the
screen go ahead and do a composer you're
gonna see we're gonna get a bunch of
commands which means composer it's
installed and this work now we are
almost done with everything right here I
I think we can move on I think we can go
ahead and install Symphony right now now
Symphony has two virgins so you're gonna
you're gonna see that we have the
website skeleton version so it's just go
ahead and let's go to our dog's HT dogs
and let's open the terminal right here
now we can do two things you can either
go ahead go to determine what right here
and change the directory using the
command line or you can just go to your
father I mean this this is specific to
Linux you can right click and open in
terminal and it's gonna open the
terminal with directory and that's great
for us so what we need to do next is we
need to install Symphony so Symphony is
pretty easy to install we're gonna use
composer obviously so what we got to do
is we're gonna do composer create
project and I just spent clear so create
project I didn't see I already done some
testing in order to install so as I said
we have two versions the first important
part is Symphony that is not going to
change so we're gonna do Symphony
you can either install website skeleton
like this or you can just install
skeleton like this now the main
difference between those is that website
skeleton will unstart everything that
you're gonna need that fuels the
template in the you know the templating
engine the doctrine start the annotation
everything that is related to symphony
to make an application work it's going
to be installed by default if you use
just the skeleton installer you gotta
get the core functionality of symphony
and anything else you gonna need you
will have to install that
now this is the fourth course for
symphony so what we're going to do is
we're gonna install the core
functionality of Symphony and we're
gonna start moving up from there so I'm
just gonna call this as F course which
is symphony course and I'm gonna hit
enter now this is the name of the folder
is going to be created in my htx now
htdocs as I said is the place with all
the application on my web applications
lives so I'm going to enter
and as you can see it's done and we have
most of the core functionality that we
get in need we have something in flex
the character container and all that
stuff that could stuff that we're going
to mean now as you're gonna see all
right here at the bottom it says two
things run your application you can
either go you know create a call so
actually this is not what I was so as
you can see you can run a web server
without even understanding Apache or
I'll stop you can obviously need PHP in
a database manager but you don't need
Apache actually you can just run the
built-in server that comes with sent me
now that that actual server does not
come built and when you install the
skeleton you have to install it now this
is a good chance to introduce symphony
flex now Symphony flex is just a plugin
or simply needed to help to install new
plugins new components in your
application the way that works is that
it used something called a recipe if you
go to disable to the website called flex
dot Symphony Symphony comm you can see
all the recipes that already exists in
the on the server you can install any
one of these that you that you want as
you can see we have two types we have
the country or country which is the
contributions by the community and we
have the official ones which are from
the symphony developers themselves as
you can see we have plenty of packages
right here and you can go ahead and
filter those by searching for the
recipes we can type server as you can
see we're gonna get the web server
bundle so as I said you can run each
application separately and I'll probably
that's what I'm gonna do because I don't
want to set up a virtual host and let me
explain to you what a virtual host it's
so we just installed our application as
you can see right here so everything is
done so what I'm gonna do is I'm gonna
try to see if that is running so what
I'm gonna do is I'm gonna go to
localhost 8080 which is where my server
is running I'm gonna hit enter as you
can see I'm gonna get this folder which
is SF course which is the project that I
just created
if I click on that I'm gonna get a bunch
of folders now
is a good chance to introduce you to to
start talking about the agitator
structure of the followers of symphony
I'm gonna start about talking about the
most important ones which are the the
SRC folder in the config folder now we
need one more file folder which is
templates but that's for the the new
stuff that which is gonna install that's
for the few stuff that we're gonna get
after we install twig now this is a good
chance to start actually talking about
MVC which is what symphony uses and
Symphony is based on MVC which stands
for for model view controller now and we
see is just an architecture that
separates your application into three
separate parts the M stands for model
which is and the model is related is
everything related to your business
logic or your actual code or database
entities or repository the V stands for
view and it's everything related to what
the user will see in simpler words you
can say that it stands for everything
related to HTML right so let's say
anything HTML related will be the view
the C stands for the controller in the
controller as we will see in second is
what helps orchestrate between the model
and the view section it's what we will
use to interact with the database and
send some data to the view and hand the
forms and much more so that's MVC now
the view in this case is the templates
that we don't have what we're gonna get
that in a second the SRC is where we're
gonna do most of our work so it's RCA
where we get away is where we're gonna
have our controller where we can have
our services we're gonna talk about
services in a when we get to those is
where we had our entities and where we
have our own logic so if we want to
create some you know some code we're
gonna put it in the SRC folder the the
folder that I want to talk about is the
config so
config is where all the configuration
that we gonna add will be living inside
this folder so as you can see this would
start our PHP you don't have to worry
about that bundles or where you want to
add some bundles now this you want to
have to actually touch or modify this
file manual
it's gotta be done by Symphony flex
whenever you install a new bundle or
something that you're going to need is
gonna be added automatically by Symphony
flex to this file right here we have
packages packages that we're gonna have
so you don't have this is gonna be
overwhelming for you the amount of
information that I'm throwing on you
right now but just to keep things simple
the config folder is where we're gonna
do most of our configuration if we need
to configure anything the SRC folder is
where we're gonna right most cloud code
the templates aware of views and HTML
files are gonna be living we have one
more folder which is the public folder
now this is the main entry to our
application so if we click if you click
on the public folder and you see this
then right here this window that I'm
seeing right now it means everything is
working and you are ready to go and
start using Symphony if you don't get
this and you'll get some some other
error which means that you have done
something wrong and it should probably
check your installation and go be some
stuff with you don't if you get some
error that you don't understand now we
have our Symphony application running
now this is not working on the public
just like this so if I so what we're
gonna do is we're gonna go ahead and
create our first controller and we're
gonna try to create our routes out on
route and see how that is going to work
so what I'm gonna do right now is I'm
gonna open up this folder this is of
course folder that we just created I'm
gonna try to open up this with my editor
and we will continue from there
all right so I just open it
the project with my favorite editor I'm
gonna use phpstorm
it's gonna help me a lot especially if
you are just getting started it's gonna
be a lot of help to use phpstorm or an
IDE
I actually don't recommend using just a
text editor or something that does
mattify provide any help or any
intellisense but that's up to you so you
can just just for your own information
so this is the HP storm and as you're
gonna see inside our controller so we
are trying to create own new controller
we have nothing now this is where we're
gonna start talking about the console so
in symphony we have a console that we
can use and we can use to to create to
generate or symbolism code that we don't
want to write ourselves so you want to
write a controller what you have to do
is you have to create file manually
you're gonna have to we had something
like the main domain controller on HP
I'm gonna hit enter I'm gonna have to do
big feet I'm gonna try to give it a name
space gonna be app controller and I'm
gonna give it so obviously is gonna be a
class and the class name is gonna be the
main main controller and this class
needs to extend the abstract controller
so images and this is the beauty of
using an IDE as you can see I'm gonna do
abstract controller and I'm gonna get
some into the sense and some help so I'm
gonna hit enter and it's gonna import
contains space for me at the bottom as
you can see it's gonna use that and I
can just go ahead and start writing some
stuff so this is how you can create a
controller as you can see you have to
write all this stuff if you don't have
an IDE if you're not you using something
that's gonna the pads and into the
system it can do automatic and cotton
for you now using the console you can
just type one line and you're going to
be done with this so I'm gonna do both
this I'm gonna delete this this file
that I just created and I'm gonna go
back to the terminal so inside my
terminal I can do so
first then I am still in there routes
where all my projects live what I have
to do is I do LS I'm gonna see
course now this is not supposed to be
here don't worry about that
of course is out further where we are
working what I do is I get a good CD
which means change directory a safe
course and I'm gonna hit enter and I am
now inside that so let's clear the
screen and to be able to access the
console what you have to do is you have
to do PHP bin slash awesome now bin
slash Khalid bin is just the folder and
console is the binary that lives inside
the bin folder so if you do the HP bin
slash console you cannot run this this
binary that we have right here if you
had enter you're gonna see a bunch of
commands now these commands are from the
console and are specific to Symphony as
you can see we are these are the
available commands we have about a list
assets cash can take the about land
right now these are the basic stuff that
comes with Symphony skeleton the minimum
version now I want to make a controller
so how I'm gonna do that
I need a command I'll make now make by
default is much included right here so
what you have to do is we have to go
back to our Symphony recipe server and
we're going to search for the mage as
you can see we have the as you can see
we have the Maker bundle right here and
it has these aliases generator make make
make redundant now you can use any one
of these four right here to install it
so what I'm gonna do is I'm gonna go
back to my terminal and I'm gonna do
composer click wire and now this
compulsory part is it's gonna use
Symphony flex to install this corn so
what I'm gonna do is you know I'm just
gonna use the alias make so I'm just
gonna copy that I'm gonna place it right
here so composer require make wait and
start the Baker bundle for me which can
I use which I'm gonna use to generate
some controllers and other self
you
all right as you can see it is done and
if we go ahead and run the PHP bin slash
constant command again you're gonna see
that we're gonna get a longer list right
now and we're gonna see this make right
here which includes a bunch of demands
like make off we're gonna get to that in
a second not in a second but we'll get
to that make command which which can
create a command for you so this is a
command and you can even use the make
man to make command a customized
commands with yourself you can create
two controllers we go which is what
we're gonna use you can made a crud you
can make an entity and we're gonna get
two instances later you can make a
fixture of form and you can see we have
a bunch a bunch of other stuff that you
can make now that's good let's keep
going with our example and we're gonna
make a controller so let's go to make a
controller and we're gonna kill it call
it main controller just like the one we
used before
so as I'm gonna enter I'm gonna get an
error and as you can see this is the
beauty of cinnamon flex so the error is
self-explanatory it needs something to
work this thing that it means is
annotation so what I'm gonna do is I'm
gonna explore what annotations are in a
second so what I'm gonna do is I'm gonna
copy those annotations and I'm gonna do
so I'm gonna copy composite required
annotations and then we're just gonna
hit shift insert and I'm going to return
key and it's going to install the
annotations for me all right as you can
see it is done now what we're gonna do
is we gonna rerun the command so we're
gonna I'm gonna hit the up car to go
through the history of my commands
I'm gonna hit again and as you can see
I'm gonna get my command and to make a
controller and I'm gonna hit return key
and as you can see it says success so
green means success it says that it's
created inside the SRC folder inside the
controller folder it created something
called the main controller HP let's go
ahead and see if that is true so I'm
gonna go back to my IDE which is
phpstorm
and indeed we have a fight we have the
main controller now let's go ahead and
open that file up and as you can see we
have something similar to what we had
before now the things that we don't have
in this route and we have this index
function right here as we see now this
is what's called an annotation now
inside
you have three ways to configure your
stuff you can either use annotations
like this which which looks similar to a
comment and you have inside you can
think we have examples of the IMO file
or example this Yammer file is just
another way to say this right here so
this is an annotation that says that
this route so this is our route we
didn't start talking about routes in a
second it says slash main and this is
the name of the route now you can do the
same thing if you don't want to do this
if you don't want to use annotations or
your own that's kind of it you can get
rid of this and you can use this routes
about yeah now this is the same thing
this is the name of the route that we
have so I'm just put that back shows a
certain C council so this is the name so
we have main if we want to make the same
thing we're gonna change this index to
main right here so that's the name of
the route now this is the path this is
what we have right here you can sleep
/name we can do some leg slash name
right here and the controller is going
to point to which action to use in this
case it should be it speed index so if
we want to want it to use something like
this we're gonna have to change this
from bank and from default control to
main controller and counter calling
index which is going to point to that
function now I'm gonna keep using and
now I'm gonna keep using annotations I'm
not gonna use Yammer but just so that
you know it exists and you can use you
want now how do we as I said this is a
route so if I go ahead to my to my
browser and I do slash main is going to
give me this right here as you can see
for now this is returning a JSON that
says welcome to your new controller and
this is the path where so this is just
some data you can have whatever you want
so we can go ahead and change this to
welcome so as you can see I just changed
this now if I go back to my browser and
I try to do that so this is my
application this is where - running so
if I do / main which should take me to
there it's gonna give me an error as you
can see it says that it's not it's not
fun that's because by default we need
slash public it's looking for the
index.php file now if I do that and I
hit enter I'm gonna get the same welcome
message as before so what I have to do
is I have everything that I need to add
to my route needs to be after this so I
had to do name like this and as you can
see I get welcome three God can answer
this way right here which means our
controller is working our rat our route
is set up and everything is ready to
work now as you're going to notice this
is ugly as hell so nobody likes to use
all this stuff right here now to to fix
this you have to to set up a virtual
house now I'm not gonna do that
I feel like this are outside the scope
of symphony it's not a symphony specific
thing is kind of it was a webserver
thing so just so that you know you can
do that and you can set up a virtual
house that will take all this stuff away
so you can have a pretty URL like for
example s of course but dev slash me so
this looks like an actual your actual
URL not disjoint that we have right so
you can do that or if you are using the
built-in Symphony server you can
actually just do localhost 8080 to the
port or you can even run the name you
can give it like soon as it comes out
there it's just the way we did a second
ago and you can do slash name now I'm
now as I said I feel like that's outside
the scope of the symphony course so what
I'm gonna do is I'm just gonna keep it
this way or we can just go ahead and use
the built-in Symphony server now this
this does not bother them so I'm just
making use of this now we just created
our first route which going to take me
to so this is a first route let's say
that we want to create our own welcome
necessary well if I get rid of main as
you can see we're gonna still get this
page right here let's say that we want
to create our own custom message and
I'll call on a home page if you want to
say so what I'm gonna do is I'm gonna
change this from main to just slash
which means be home so this is the road
route there actually if you want to cut
their battery of other applications
I'm gonna change the name of that rug to
home and I'm gonna keep the function
index and I'm gonna keep these same s
actually you know I'm gonna get I'm
gonna get rid of that and I'm gonna
return any response now what's a
response a response is something that
every action inside Symphony it needs to
reach out I'm talking about the actions
and not every single function but this
is an action so each action within a
controller needs to return a response
and that response lives inside symfony
components HTTP foundation so don't get
this messed up a lot of people import
the wrong namespace and they just spent
three days trying to debug something
that is very simple always pay attention
to the namespace that you are important
in this case we need HTTP foundation so
we're gonna hit enter as you can see I'm
using phpstorm so it's going to import
that automatically for me and you can
just do semicolon at the end now this is
empty so if I go ahead and try to
refresh this as you can see I'm gonna
get an empty page because I did not add
anything to this response now what I'm
gonna do is I'm gonna just try the
string that can chase some HTML so I'm
just gonna do something like h1h well
and I'm gonna just do Welcome Week that
and I'm just gonna go ahead and refresh
my page and as you can see I get my
message welcome free code camp which
mean this is working so our index has
changed from just uh you know that
regular Symphony working message to this
custom control controller action that we
just made so we just made our first
route now let's go ahead and try to
create another function so another
action with another route just to get
familiar with pista so what we're gonna
do is just below this we're going to
create another action so let's do public
function and you can college whatever
thing you want so in this case I'm just
gonna call it custom and just gonna be
like
now this is just a function so if I just
try to do something with it it's not
gonna work now what I need to do is I
need as I said before to set up our
route for this because I want this to be
accessible from the browser so what I'm
gonna do is I'm just gonna do I'm just
gonna copy the same route and I'm gonna
place it right here and I'm gonna change
this from just slash because we have to
so I'm gonna change that form / - slash
custom let's say that's what we want we
want this action called custom now I'm
gonna change the name so I'm going to
change that to custom as well and we
need to return something so if I just
leave it like this empty and I try to go
to that URL as you can see I'm gonna get
an error they control and does not
return their response an exception the
controller must return something that
extends this response object so it's
must return a response now let's go
ahead and return the response so we're
just going to return your response and
I'm just gonna do something like yeah
let's copy the same thing that we did
right here and it's always just give it
something like custom page all right so
I have that set up I'm gonna go ahead
and refresh this page and as you can see
I'm gonna get my message custom page so
that's it we created to consume we
create to the controller we created two
routes and we can access them both now
let's do something that's let's go ahead
and talk some more about routes now
we're gonna get to those in a second
we're gonna start we're gonna explore
them further more but I want to do
something let's say that we want to
create a page this is welcome to some
username that we're gonna enter now we
can we're not gonna use a form or
something we're just gonna use the URL
so now we're gonna change our custom
function that we just created right here
to do that's proper to do that for us so
what we're gonna do is we're gonna
change the URL now as I said we want to
be able to do something like slash
username I'm gonna do like three so I'm
just gonna go three like that for camp
when I hit enter
see it's gonna say that this rug does
not exist that's because we have not
configured yet so that's what we're
gonna try to do now how do we get it to
take but something that is going to be
dynamically entered right here we gotta
go back to our rug to our custom slash
and what we have to do is we have to set
up some property that is going to be
dynamically changed and how to do that
we're gonna use the curly braces like
this and we're gonna give it whatever
name you want so let's say hello name so
this name right here is going to be
accessed so we're gonna access that and
that is going to be the man that we can
agree so instead of welcome page we're
gonna say it work to that username and
how do we get access to that username
right here so that's what we're gonna
see right now
now inside each action we have access to
something called the request now the
request is where all our do is so
basically is a request that comes from
the client it includes a lot of stuff
like the data that he sent the queries
that he sent because is I just like B
and a bunch we still probably his time
zone and a bunch of other other
information that we use now to get
access to that request what you have to
do is within the parameters that you
have for your function or your action we
can just use the equals now again you
need to pay attention to the name space
you don't want to import the wrong name
space for the request you want to import
the HTTP foundation one don't do the
browser kid stuff
whatever just do HT import the HTTP
foundation namespace pay attention to
that it's gonna save you a lot of time
and it's gonna avoid some headaches so
requests let's give that a name so if
you have requests like that and we got
access to that now I'm gonna have plates
get you dog just to get rid of that line
and next we can go ahead so how do we
take a look at requests how do we know
what the request contains now we then
simply we have a function called dump
now we use dump too it's similar to var
dump but it's actually better it so I'm
just gonna show you how it looks like in
a second
so you can use dump to dump the requests
so let's go ahead and do that we're
gonna dump the requests and we're gonna
see what the requests tanked now if I go
ahead and just refresh this page it's
not going to work as you can see it's
gonna tell me that this custom does not
exist that's because this is ugly so I
need to enter the name
I need this name to be to exist if I
want this to be optional so as I said
you can see we don't have it right now
what I can do is I can add this it's
explanation mark which is going to make
this optional for me so if I go ahead
and just save this and refit page as you
can see even if I don't enter any user
name is still going to work and as you
can see with it's working we still have
an error but it's a different error but
that is working as you can see we got
custom without a user name and it's
working now as you can see the error is
that we are trying to call a function
that does not exist this dump function
now to use that we have to go back to
our symphony recipe server as I said we
are using the minimal version which does
not include anything and we have to go
and look for you done so I'm gonna type
dump and as you can see we got to get
these symphony of our thumper so what we
have to do is we have to install that
let's go back to our terminal and let's
do composer require and I'm gonna use
this alias right here which is dump and
it's just glued down
as you can see it's done and if we go
ahead and try to do this actually before
i refresh the page actually let's just
go ahead and refresh this as you can see
this is what the request looks like now
the dump is nicer because as you can see
if enfold you don't have all the
information like you don't have a
million lines that you have to scroll
through you got all the basic stuff that
you're going to need request so this is
what the requests contents and you can
go ahead and fold and unfold whatever
you want as you can see we have the
server and we have all the information
that we possibly mean now well we're
just doing that one thing that I flew
that I didn't do in the beginning and I
feel like somebody it's probably gonna
be asking about this I want to use the
built-in Symphony just so let's say
somebody don't want to install all this
stuff so what I'm going to do is I'm
going to use the built-in Symphony and
I'm going to show you how to use that
and even to get rid of all this nasty
stuff that we have back to you so I'm
gonna go back to Symphony recipe server
and I'm gonna look for it served now
this is the web server that I'm looking
for so what I'm gonna do is I'm gonna go
back to my terminal I'm gonna do
composer require as you can see it is
done downloading and installing the
server I don't have to do anything else
trying it thanks to Symphony flex now
all I have to do is run the server so
how do I run that server now what I'm
gonna do is we have to so actually you
can just go ahead and let's go gage
patreon slash console so we're gonna run
this from a command so if I do PHP bin
squash console you're gonna see that we
have a new set of new installed commands
which belongs to the server namespace
it's called the first one server run
which we're gonna use and there's also
server start which starts which do does
the same thing a server run but it does
that in the background so I'm gonna show
you the difference in second actually
let's do it right now so if I do gauge B
bin slash console server run as you can
see it's gonna take this terminal and
it's gonna keep using it it's gonna post
whatever requests that I make
like to so this is where my application
is living as I mentioned if I go back to
as you can see 127 dot 0 dot 0 dot 1
it's just me it's just the address for
localhost so if I type localhost is
going to mean the same thing now the
port is the most important thing it's
8,000 so let's go back to our web
browser and let's try to do that I'm
gonna leave this open right here and I'm
gonna do localhost
now it says 8080 so I'm gonna change
that to 8,000 and I'm gonna hit enter
and as you can see I'm gonna get the
same thing welcome to 3 welcome free
podcast now you're not gonna get the
same chunk of as you have right here
which is of course public index dot PHP
and then you get access to what you want
but you can just exit that directly from
here now even this can be it could be
customized you can make this like of
course the div or dot local whatever you
want but I'm not gonna bother with that
stuff right now so as you can see we get
the same thing so I can do just custom
right here and I'm gonna get access to
the same thing so that's that that's and
as you can see looks nice and it works
the same way as being server so what I'm
gonna do is I'm just gonna get rid of
all this because I don't want to work
with this anymore and I'm just gonna use
the built-in server that I use now now
let's go back and see the difference as
you can see this is going to to be
debugging and give me all the
information about what's happening right
now and that's for the server run now if
I want to stop this all I have to do is
hit ctrl C I'm gonna do that ctrl C and
it's going to get me out of that now the
server is no longer running as you can
see right here so we have to do is we
have the other option which which is
server sparked now service start is
going to start the server but it's going
just to start it and give you back your
turn around it's not going to be
outputting this anywhere it's gonna be
in your log files for all that Symphony
project but it's not going to give you
like real time stuff that you can see
right today
unlike the the server run now to start
this server all you have to do is server
stuff and
that server now what I'm going to do is
I like to actually see what's happening
on times time so what I'm going to do is
within PHP spam I have access to a
terminal that's that's built-in within
the IDE so if I do all f12 it's gonna
give me this terminal right here and
right here I can do PHP bin slash
console I can just like whatever command
I want I'm gonna do it the same thing so
server run and it's going to run the
server for me right here and I can just
close it and open it whenever I want to
and that's pretty neat and nice man I
didn't take advantage of that so that's
what I'm gonna do I'm not gonna use this
of the server starts in the background
whatever it show just trying to show you
what you can do with it so I'm gonna
clear everything and we can go back and
keep you working on our custom that is
going to greet the user so let's go back
to our custom function we're gonna
refresh this and as you can see we're
gonna get the same thing and we're gonna
move keep working on that now how do I
get to all the parameters that I'm gonna
pass after the base now for now I don't
have anything but if I take a look at
the request I didn't see I had nothing
right now
and given the attribute so in the
attributes so request query whatever I
don't have anything in the parameters
the attributes I have some things so I
have the route which is the custom and I
add name so name is what I had to
interact with this and it's currently
not that's because I allow it to be more
when I defined this right here this is
the controller that is going to use and
this is the route around as you can see
we have name again now let's go ahead
and try something let's enter something
like this let's take a look at the
attributes again and the parameters as
you can see we have name three code can
and the array is gonna be the same thing
now the request is still empty the query
is still empty everything else is still
empty because we are using this around
points we are getting that from the
attribute now how do we get that from
inside our action what you have to do is
from the
quest we can call the get function and
it gets function it takes a key like for
example in name so what I'm gonna do is
I'm gonna give it the query the
parameter name that I have right here so
I'm just gonna pass bang and I'm going
to refresh this now everything is going
to disappear all I'm gonna get is the
name that I class right here let's get
rid of that and see what's going to
happen so it's gonna say that's an
undefined opposite that's because that's
great because I have slash something
which is a magic thing what I have to do
is get rid of that slash and I can do
just custom and it's gonna give me back
mom so let's just all we have to do
right now so let's go put it back
everyone as you can see I get everyone
so I want to concatenate that right in
the response let's go ahead and do that
so I'm gonna do welcome and let's just
do some basic automation right here and
we can just do requests I'll actually
you know what let's just use this and
I'm gonna save that run to called name
and let's just do that name right twigs
let's go ahead and refresh this and as
you can see I get to welcome everyone so
if I change this to 1 then I get welcome
back that's just a welcome oh and that's
pretty much it for this part I feel like
this took so long so now what we're
gonna do is we're gonna start talking
about views so as you can see this is
just returning some ugly stuff for us as
we turn in just this response HTML and
you don't want to do that so how much
shimmer can you even fit in this small
string right here so what we're gonna do
is we're gonna start using fuse and for
you the template engine that we're going
to use is called twig so this specific
Symphony now we cannot just go ahead and
start using twig because we have to
install it first so let's go ahead and
search for twig and as you can see we're
gonna get some stuff with bridge bundle
lips or this extension extensions and
all that so what I'm gonna do what we
gonna do is we're gonna go ahead and
install the twig bundle which is going
to inspire and everything that we're
going to need to start working with this
so again I'm gonna go back to my
terminal
I'm gonna do compulsively Park I'm gonna
placed template I'm gonna enter and it's
going to install with templating engine
for me and I don't have to worry about
anything else alright as you can see we
have twig installed now let's go ahead
and see out with music now the first
thing you gotta know is after we go back
to our application we have a new folder
it's called templates now this is what
out what I was talking about this is
where this is the EM we see this is the
V section of that ending see so this is
where all the viewers are going to live
inside the templates one other thing
that you're going to notice inside our
packages we have a new apply it's called
twig dot Yama so this was much initially
here it just added right now even this
was not here we just created the way we
installed annotations but within twig
Tamil you can see that we can get rid of
some stuff so this is the default path
where it's going to look for the views
as you can see it's in slide templates
and some stuff some straight variables
and all that you don't need to worry
about right now now let's go back and
close some of these stuff so nobody gets
confused we can go ahead and set up our
routes for our five now let's go back
and do this for both our index dot HTML
and our custom index action and the
custom action now instead of just
returning something like this we turn
your response what you can use is to
just build return this render now this
refers to this render as you can see
this render function is not inside our
main controller but it lives inside the
abstract controller right here so we're
gonna use that function as you can see
this render takes some stuff the first
thing it takes is the place where that
template is now I'm gonna show you how
that works so if I do something like
home slash index dot HTML code twig and
I just yeah this is going to look for
that if you within these templates now
home is just the folder index dot HTML
the twig is the extension that you
should be use for twig files
we don't have this file right now so
this home we don't have even that
smaller as you can see the only thing we
have is baseball HTML or twig now if I
just leave it like this and I try to go
to that route which is okay I get rid of
custom image just try to get to that
place as you can see it's gonna tell me
that it cannot find the template inside
the templates folder now what we have to
do at this point is go ahead and create
that so what we're gonna do first
inside templates we then create the
directory which is called home and
within that within their home territory
we're gonna create our index dot HTML
but with some index.html go click file
I'm gonna enter and we can have whatever
we want right here so I'm gonna just do
an h1 h1 h1 and we're gonna go on
Twitter like that so let's go ahead and
refresh then see what we're getting hit
and as you're gonna see we get welcome
from twink now it's pretty much the same
thing but this is a twit file it's
separate you can have whatever you want
now we did that from the main controller
let's go ahead and do that for the
accustomed inmate at the index action
let's go ahead and do that for the
custom action now we're gonna get rid of
get rid of this response that we have
right here and we're gonna do return
this render and we're gonna render
something so we're just gonna use the
same although we're gonna do home and
we're gonna call this custom code HTML
code quick so the same thing like right
here
so as usual we gonna do custom and we're
gonna get an error it's not gonna be
able to find the template that's because
we haven't created it yet so let's go
ahead and do the same thing let's create
a new file it's good custom dot HTML
built way I'm gonna enter and let's do
something like h1 welcome so if you
remember correctly in the response we
had something like welcome in the
username so how do we get access to that
username right here so that name that we
just enter like here so how do we get
access to that as you can see it's just
going to give me one
well you can just not do name like this
it's not going to work because it does
not even know what make is so what we
have to do is from the controller we
have to tell it that we need to pass
this name to this view so that this view
can be able to use it now how do we do
that all you have to do is send
everything in the second parameter in
the render function I'm gonna put a
corner after the name I'm gonna send an
array which is gonna be all the data
that I'm gonna need and as I said I'm
gonna give this name so the first thing
is the sock this is just a regular HB
array so the key is going to be the name
that is going to be used then the actual
template here in the actual with you so
what we're gonna call it I'm gonna call
it name you can call it whatever you
want
the second thing is the value in this
case it's gonna be the name variable so
I'm gonna pass that now I'm gonna go
back to my custom dot HTML you can
measure just do something like this it's
not gonna work as you can see it's going
to render that you know that as a string
now Twitter uses a separate special
syntax is gonna use something like
Angela of usually as use its use two
curly braces and you can put whatever
you want within that so everything
between that will between it s PHP or
twig so in this case what we need to do
is you cannot do the name like this
that's not gonna work it's gonna tell
you that it does not does not know what
this character is you have to pass the
variable just by using its name so
welcome to curly braces and the name of
the variable which is name now let's go
ahead and see that as you can see it
says welcome to free can now basically
you're almost done with the controller
and user you know how to set up most of
this stuff that you basically mean now I
want to add some stuff I want to confer
I want to add some CSS and some Jas to
this so what I'm gonna do is I'm gonna
use bootstrap so let's go ahead and get
bootstrap I'm gonna get that from some
sort of CDN and I'm gonna take whatever
I'm gonna need so basically uh for now
I'm just going to need the bootstrap
don't wind up CSS I just need the CSS
stuff so what I'm gonna do is I'm gonna
copy so this is the first version so I'm
just gonna copy
yes and I'm gonna go back and see how I
can include the right ear
now before I start using bootstrap I
want to mention one other thing that you
can do with twit which is the mint and
what you want to why you want to use
something like twig now let's say that
you have like a navbar that you want to
be that you want to have to be repeated
between all the views for example we're
gonna have a mouth all that it's going
to take us to the home page it's gonna
have the logo on it and all that so how
do we do with that so basically that is
going to be repeated and you don't want
to add to copy that Auto good place you
don't want to copy that each time you
need that it's gonna make it harder for
you to change it if you want to update
something you gotta go you're gonna have
to go through all the million views that
you have it's not something recommended
to use what you can use is something
called a layout so for example this
based on HTML twig serves as a layout so
we can actually use it as you can see it
has a doctype it has the HTML the head
and the body and we can actually just
include bootstrap right here so let's go
ahead and try something like that let's
go ahead and add wood strap right before
the site sheets so as I said as I said I
just copied this CDN but yes of
bootstrap and I just included it right
here but as you can see this is not
going to be used yet if I take a look at
the source code right here if I do a new
page source as you can see it just says
welcome free code camp and it's not even
valid HTML it does not have debug type
and HTML tags not that so what we have
to do is we need some way to tell this
to use this but just put this content
inside the body
now we're gonna notice something called
blocks we have blocks right here so the
main one I want to focus about right now
is the body so how how is this body
block working right now so you can
define a block like this so this block
is going to be filled with something
when called in other views now before
you can even do that we have to extend
this based on HTML but we know that we
have a key so how we can do that we can
just go to the first line of our
application we can do optional curly
braces and
2% a percent you know simple and we can
do use the extent to see extent and it's
going to ask me it's not going to ask me
but second thing that I can provide
after that is which layout I want to
extend so in this case I want to extend
the basics of HTML there so what I'm
gonna do is I'm gonna do base don't HTML
don't wig okay
let's go ahead and see what that's going
to give us so I'm within the custom
location archway I'm going to refresh
this and as you can see it's gonna tell
me that this view right here is extended
and under view but we can not have just
tags to be thrown all over the place so
this needs to be placed within another
plot and how do we specify that blog for
example in our case we want to put that
within the body of that word layout so
we can do something like this we can do
the same thing do block body and we can
end the block right here and inside that
we can put whatever we want to be put in
the body of our five so if I do that as
you can see it's going to work now we're
going to notice that it's changed a
little bit that's because if I take a
look at the source code so if I do that
you're gonna notice that it's extending
that basically all the best layout and
the best layout is including the
bootstrap J's which means we can now use
bootstrap in our our files now let's go
back to our main as you're going to
notice it's still ugly and it does not
use and it would struck let's do the
same thing let's extend people's
gelatine spend the base layout for that
so I'm gonna do stems and based on HTML
but with and as before we're not allowed
to put just all this anyway we want
we're gonna have to use a block so let's
put that in the blog but and let's end
the blog look and we have that welcome
quick let's go ahead and refresh this as
you can see it welcome front page and we
can make all sorts of changes that we
want for example let's put this block
inside a container so we can do that
simple stuff and everything is going to
be centered within the container
and we can have our as I said let's go
ahead and steal some something from the
back detection and let's just copy
something from that and we can use it
you know just to demonstrate this so I'm
just gonna steal this and I'm gonna go
back to my layout file and I'm gonna fix
this along here so if I go ahead and
refresh you're gonna see we have enough
wire right here now this is a big big
big properly but as you can see we have
our search we have everything that is
going to be able to it now let's change
these to an inspector we have lights
here I want to have the arm and I want
to have some other page so for example
for example the arm now should take me
to this home that I have watch it so
let's go ahead and change that let's
change some stuff you can change this to
feed now this is where I want to talk
about the names that we were specifying
for these routes right here so this is
where the names are going to be useful
so within the within twig if you want to
generate a URL that points to some
action you want to do that right here so
you can have like any any URL that
exists in your application if you want
to rare to actually generate that route
what you have to do is use two curly
braces so that's syntax for twig and you
can use the path function so if I do
path like this and I'll try to give it
so the second parameter needs to be the
name of that route so in our case the
name is home so if I just copy this and
I go back to to the path and just paste
that in there if I go back as you can
see this is before even we
right now is just say this hashtag as
you can see at the bottom keep your eyes
right here I didn't see it suggest a
hashtag we don't want to have that we
want to have the home page that we want
that we have allowed okay so I'm going
to refresh this as you can see the name
changed and even you are out so you see
right here the URL has changed we have
local hometown so if I click that we're
gonna take me right here let's go back
to the custom patients to look at it's
working it says welcome something but if
I click on that it's gonna take me to
welcome from twin so that's how we can
generate a URL now how do we generate a
URL with parameters now we can just get
rid of this home right so we're gonna
leave that and link I'm just gonna get
rid some I'm gonna generate a link so
I'm gonna say create for example now how
do we generate a URL with parameters now
as before we're gonna use the curly
braces we're gonna use the calc function
we're gonna give it the name of the
function of the action that we want to
use in this case it's called
custom so let's come to that let's put
that in the fat and how do you wanna
pass Parana pass parameters is this is
by using the second argument of the path
function so we gotta use something that
looks like an object in JavaScript and
the first name the first thing you're
gonna pass right there is the parameter
name in this case it's called names so
let's go ahead and do name like that two
common points whatever you want to call
them and the second thing is going to be
the name or the parameter that you want
to that you want to use you can pass
something dynamic or in my case I'm just
gonna pass the name that I just use
right here so I'm just going to do that
and I'm gonna refresh and see if this is
going to work so as you can see I got
rid of everything right here but I have
my tweet grants which should take me to
the custom slash that URL so if I click
that indeed it's work and as you can see
that is working properly and perfectly
fine now that we are code that we have
covered the basic stuff of controllers
routes and views what I want to do next
is focus on the doctrine or the database
related stuff so we're gonna go ahead
and start writing some very basic stuff
so the first thing we're going to need
to do obviously is install doctrine
because we don't have that can stop and
to do that we're gonna go ahead and head
to our Symphony recipe server we're
going to search for doctrine and you
gotta see you're gonna get a bunch of
stuff now this might confuse you a bit
because there is no doctrine related
stuff directly but we have to do
something is but we have to actually
search much for doctrine but or and so
if I do or and like this it's gonna give
me some some packages and the package
that I'm looking for exactly is this
Anthony RM pack not to install it this
is going to install everything related
to doctrine you don't have to worry
about giving anything else this is going
to give me a most of the stuff that
you're gonna need so what we got to do
is we gonna use the alias doctrine to
install this and we're gonna go back to
our terminal and we're going to do
composer require em abduction
yeah let's use our M shorter so we're
gonna do our m and we're gonna hit
return key analyst let's just leave it
install words needs alright so we have
some stuff that's been done as you can
see it everything is installed it's it's
tough and as you can see it's gonna tell
you to modify your database you are
right and think and they thought
environment but we're gonna take a look
at this in a second and as it's gonna
tell you that you can confirm your DNA
so that's where we can configure my
sequel or whatever driver we want to use
and it created this doctrine Dhamma
within our configuration file now let's
go ahead and take a look at these files
quickly now the first as you can see
inside our SRC so let's start from the
bottom I'm gonna mix this up so as you
gonna notice inside our packages we have
a new wild-card doctrine and doctrine
migrations so I'm gonna go to doctrine
and explain this stuff so the parameters
as you can see this you can set this
parameter if if you don't have anything
set within your within your environment
file so we're gonna take a look at the
environment while actually just start
with it
is very simplest one now as you're gonna
see it sits you can find the
environmental part in your root
directory so it's not within any folder
you can find the dot env file if you
open that up you're gonna find that we
have a bunch of stuff so this is
Symphony relate to start didn't need to
worry about this but this is the
doctrine stuff which which matters to us
right now as you can see this is the
database URL this is the most important
part of the configuration and it's this
is where you really find that you're
going to be using my sequel and it's
where you define your username the
database password your look your you
know your address and your quote and
last your database name now we're going
to come back to this where we need to
configure and create our database let me
just explain some of this stuff that you
can see it right here
now this our amp section we don't even
need to worry about that especially that
this is for beginners and we don't look
at that now as you can see it's gonna
say the driver that it's using is my
sequel the server version 7.5 5.7 it
doesn't matter the charge set is that
and the most important thing is the URL
as you can see this URL is getting that
from the environment twice so this is
how you get something from the
environment but even a result the
database URL in this case it's my sequel
so this value is just taken and being
copied and being pasted here so that's
the most basic stuff that you need to
know so if you want change something for
your database you want to change it
right here for example there the
username the password the password the
port or the database name these stuff
needs to be changed right here now
within SRC folder you get a notice that
we have doing things created for us we
have entity migrations and repository
now I'm not gonna be using migrations in
this video but it's pretty simple it's
if you if you have ever used ever before
it's pretty much the same thing and you
can just check the documentation if you
want to use those I'm just gonna keep
stuff pretty simple and I'm gonna be
doing what I usually do so entities I'm
gonna come back to that well story I'm
gonna come back to that
migrations as I say I'm not gonna use
those so that's it all these are
see formal now that's pretty much all we
need to know about this stuff now how do
we interact with the database now first
we need to have a database to interact
now we can start by changing the
configuration inside the in environment
type the first thing we need to do is we
need to change the username now the
username if you remember is root the
password is whatever you set when you
install that so my case it's six zeros
the port is gonna be pretty much the
same I'm not really sure if it's the
same or has changed I'm gonna check and
last here we have the database name so
I'm gonna call this as a course which is
simply course and I'm gonna save
everything right here now one more thing
that's been changed is its ID the HP bin
slash console if you take a look you're
gonna say that we have a bunch of new
functions or commands which belong to
the doctrines but let's see if I go up
the font is relatively large that's why
you are seeing these stuff right here
as you can see we have a bunch of
commands that's been installed and when
we install doctrine RM and then we can
make use of peace without first when we
gotta take a look at is database v8 now
database create is going to create the
database for us now let's go ahead and
see what what databases we have like now
so let me just see how can I find that
so I think I can get rid of this is this
and that was trap and let's go ahead and
do localhost 8080 not this 180 this is
our symphony but in server right this is
how to access your actual
HP my admin server so I'm gonna do PHP
my admin like that I'm gonna enter as
you can see it's gonna ask me for the
password in the username I'm gonna enter
those I'm gonna hit the return key as
you can see we have our databases right
here now as you can see we have
information my sequel performance insist
now how do we create our database that
we just configured right here so I'll do
it waits and of course now we can just
go ahead and create this mining Lee if
you want to nobody's going to know
nobody's going to complain about
that but I like to take full advantages
advantage of Symphony so what I'm going
to do is I'm gonna do the HP advanced
launch console I'm gonna call doctrine
and I'm gonna use data base namespace
and create and I'm gonna hit enter as
you can see it's gonna tell me that this
is not to Allah allowed to connect to
this my sister and one way to fix that
would be to search all the answer using
Google so let's go ahead and do that and
as you can see on this page we are you
gonna scroll down a little bit and of
course we don't have and my secret
installed or the see a lion spots are we
gonna do it we just gonna copy this
command that we have right here and
we're gonna run that on our PHP my
admin' so I'm gonna go to my sequel this
is the database that is causing this I'm
gonna go to my sequel right here and I'm
gonna paste whenever I copied from the
website I'm gonna go and change route to
my IP I'm gonna change that to one point
seven zero than 0.1 one under identified
by six zeros which is my password with
grant ouch I'm gonna hit go and see
what's gonna happen and it seems like I
have some sort of mistake that's because
it is on right here I need to change
them so I'm gonna go against York I'm
getting get so it seems like something
something happen I'm gonna go back to my
tournament and see what's gonna happen
like now so let me just clear this and
it's do PHP then slash console function
database create and indeed it created
the database for us so as you can see
symphony you know something he calls
database was created let's go ahead and
see if that's correct
I'm gonna refresh this let me fetch this
and indeed as you can see we have our
database right here now we need to
create some sort of tables so how do we
create a structure that we have right
here now what I like to do is create
from symphony itself now each table
right here in your database is
represented by on symphony site is
represented by something called an
entity now an entity is just a regular
class that would have some properties
now each property now the class itself
is going to be a table and each property
within the class is going to be a field
within our column within your table so
let's go ahead and make a very basic one
now obviously I'm gonna take advantage
of Symphony and I'm gonna use the
console what I'm going to do is I'm
going to be PHP a pin slash console and
I'm gonna use the make command and I'm
gonna make an integer I'm gonna junky
and it's gonna ask me for the name of
the entity that I want to create let's
say that I want to create something
called post are we gonna have some posts
in our in our database and all that so
let's create close now it's gonna tell
me if you want to add some properties to
this one now of course I want to add
some stuff I'm gonna add a title I'm
gonna add for example a description
now before I made any changes after
write create the property is gonna ask
me for the fields right now in my case
it's going to be a string and it's going
to be just 255 does not matter and can
this field being all in the database I'm
gonna tell it that this cannot be null
at the moment but I can change that
later if I want so I'm gonna hit return
key and for now I'm just gonna keep a
bit title and that's it I don't want to
have anything else so what I'm gonna do
is I'm gonna hit the return key to start
adding fields and as you can see we have
green which means that this entity was
created now you're gonna see that this
kind of asked you to create migration as
I said I don't like use migrations but
they are pretty useful if you want to
use them for yourself you can check the
documentation for anything related to
migrations is pretty easy
they are pretty easy to use now let's go
ahead and see if we have our class now
if we have our table of course we don't
have anything right now we still have to
migrate everything from symfony to our
database now before we do that let's
take a look at the entity that was
created for us and we have oats postdoc
HP now as I said this is just a regular
class with Santa
as you can see its class it was not
extended and again and we had this
entity which means that this this is the
repository for this class now we don't
have you don't have to worry about to
report story I'm going to explain that
we get to it and we have some properties
now this is the ID for your class which
is as you see it has this are M ID if
this annotation ID and it's generated
value and it's economy of type integer
so this is where all the types are
coming from we have our title and now
everything needs to have a getter and a
setter as you can see we have get idea
how to set IV obviously there cuz it's
also uncommented and we have get title
and we had set what a title which we're
gonna use to to set or get in title
identity now how do we create this table
how do we migrate this to our database
we had to go back to our terminal and
you can even make a migration if you
want to I'm not gonna do that that's
what I'm gonna do is I'm gonna be PHP
pin slash console and I'm gonna do
doctrine and not database but schema so
this is something related to the schema
that we are dealing with now this is a
schema so this is the scheme of our
database this is the table that's within
our database are we gonna use names a
schema and we have updates or create so
if you don't have anything you can use
create which is going to create the
schema for you or if you are making
updates while you are working on it you
can use the update now you can even use
updates if you don't have anything and
still going to work if I do update and I
just hit enter as you can see it's it's
not gonna tell me anything so I gotta
tell me that so it's gonna tell me that
you shouldn't use this and production
environment obviously but it's not going
to do anything just kind of asked me to
evil force this command or used um
sequel to see what's to see whether it's
going to be executed now let's go ahead
and take a look at the sequel so let's
go I'm sequel and as you can see it's
just a regular sequel you know like the
one you used to write when you were just
using sequel HP now to execute this what
you have to do is not use for dump
sequel but you have to you
course let's go ahead that as you can
see one quick query was executed and the
database schema was updated let's go
ahead and take a look at the HP my admin
I'm gonna click on the database name as
you can see we have our table which is
post now this is correct we have a post
right here as you can see this is
structure this is an ID this is a
primary key and we have our title right
here now let's go ahead and see how we
can interact with this from our
controller let's say that we then so
let's do something let's let's change
our application mint language let's say
that inside our inside our custom when
we want to see some you know when we go
to the page of customer slash name we
want to actually persist that user to
that name to the database as a post I
know it does not make sense so what we
gonna do it we had a changes to create
post let's go create like that oh you
know what it seems like it's about time
to create another controller so let's go
ahead and create another controller so
we get that we get more specs let's go
page we have instructs console let's
make an adventure we're gonna call this
post control it because it's going to be
everything or it's related and in this
case so we're gonna do post controller
as you can see it created that and one
one thing you're gonna notice that once
we install the twig bundle it's gonna
install the it's gonna create the
controller and it's going to create the
templates relating to that controller
because it knows that you are using twig
or a templating engine so that's a plus
in this case I go to templates we're
gonna see that we have post between
relates to our post controller let's go
ahead and open that up as you can see
this is a place where we gonna we were
gonna display for example all our posts
so what we're going to do is let's go
ahead and let's leave this as it is
right now let's go ahead and create
another action we're gonna call this
create in this case we're going to need
the request because we need some sort of
data that we're gonna use so we're gonna
do requests like that and let's take a
look at the namespace that we imported
we have nothing so I'm gonna do all
Spencer and I'm going to import the
class
foundation now it's not going to do
anything obviously because it's empty so
the first thing we need to do is we need
to purchase an object database now
everything ichiro in our database is is
an object for example if we want to
create a new post in a title what you
have to do is you have to create a post
so we got to do a new post like this
post is this then inside the entity so
I'm going to do that
and from pose I can use my getters and
set it so I'm gonna use set title so I
can set a title for my post so I'm gonna
do sit tight like this and this is going
so nothing is going to happen obviously
all right now now of course we still
need to return response now in this case
we're gonna return a few or something so
we're just gonna get to that and we're
gonna get to that in a second now this
is still not a proper action because we
forgot one more thing which is the rug
so let's go ahead and set up the routes
so obviously my gonna watch everything
I'm lazy so I'm just kind of copy this
and we're gonna make this slash create
now I actually I want to make this
slashed post slash create because it
makes more sense but one thing that I
don't like is me to myself I don't want
to have / / / / / / index / / / edit so
what you can do is you can set a route
or your entire class it's going to be
set as a prefix so I'm gonna copy the
same route that I have right there
before my class not before my action or
anything before my class and I'm gonna
change that to slash post the name is
going to be post dot because I like to
separate my name's using that so this
right here is no longer slash post / box
/ post so what I'm gonna do is I'm gonna
get rid of it so you know what and show
you I know that this looks very abstract
to you so I'm gonna do is I'm gonna
comment whatever I do right here
let me see if this is fine fine so what
I'm gonna do is I'm gonna get rid of
this rub that we get that in a second
there is a command that you can use to
be both audio routes so what you're
going to do is you do PHP bin slash
console and you will be back but I'm
gonna hit enter as you can see I'm gonna
get all the rights that I have set up
right now
now you're gonna see that this is post
doc post and this is slash this slash
post large post that's because we are
using this prefix right here so if I
change this to lunch something just to
see that I'm gonna show you something
these one are going to change from slash
posts that close to slash four slash
something it is going to be posted on
something okay as you can see post on
something and it's bad for our sample so
let's put this I'm gonna call this index
for stock index and I'm gonna call this
just slash because it's the index within
our post right or if you want to call it
like in name spit okay so let's go ahead
and create our second one so I'm gonna
copy this as I said and I'm gonna call
this create so let's call this Y and
let's give it a name create and we have
requests let me just update the dog to
get rid of that line and we have our
create so let's go ahead and take a look
and see what we're gonna get right here
so I'm gonna go for router again as you
can see we have slash slash cool yeah
now this is going to give us all the
posts that we have and this is going to
allow us to create a new post now is
this going to be persistent to the
database absolutely not because we have
no way to tell it that this needs to be
sent to the database so what you know
what we need in this case is something
called the entity manager and the entity
manager is what actually connects and
talks to the database so how do we get
that which is kind of call this e/m
which stands for entity manager are we
gonna use this which refers to our class
and we're gonna get to get dog training
which is a function from this abstract
for a controller that you are extended
now we are getting doctrine but from
duction we need the entity
so what we're gonna do we're gonna go
get manager like this and right here we
have an entity manager so how do we use
that to persist now we're gonna use
entity manager and from that obviously I
said it before we have persist which
going to persist and save everything to
the database let's go ahead and serve
the persist that so we gotta be trying
to we are trying to create this row in
our database that is going to be called
it's going to have a title so one thing
that is going to be creative right here
is an ID of one and it's like look of
this one right here let's go ahead and
do that so this should do something and
you know what let's do something let's
return and your response I'm not gonna
be kind of view right now need it no as
you can see I imported the wrong
namespace and just get rid of this
response all right here and import the
correct one which is from HTTP
foundation and what we want a return is
just the post was created and as you can
see in a second it's not going to create
that post
let me just update the bug to each other
we turn and let's go back to our
application and we need to access that
forum post slash create as you can see
if it's kind of telling me that the post
was created but let's check our database
and it's full of lies this money did not
create anything that's because after you
persist you need to call another
function called from the entity manager
you need to call the flush now this is
just going to construct the insert query
it's not going to actually insert it but
to persist everything and send all the
commands the database you need to call
flush which is going to actually execute
that query that you just created music
says now normally you want to call flush
after everything so if you have like
multiple commands right here or multiple
lines that are going to persist or
whatever you want to call flush after
that you don't have to come flush up to
each one of the purses now let's go back
and see if our query is going to work
and then a refresh as you can see it's
post was created let's go ahead and
check it's lying to us and it's not
lying it's actually working at it so we
have this is going to be our title we
have our record right here so how do we
actually get this so we just inserted we
just made our first interaction with the
database how do we actually get this
value from the database so we need to
have some sort of a way that says so
this is just creating I want to have
something that that is going to display
the first one so we're gonna set up two
things we're basically we are basically
making a crud right now a crud and let's
go ahead and try to do that so let's say
for our index action we're going to
display all the posts that we have no
pagination or whatsoever we're just
going to display all the positive yeah
how do we do that we're gonna create a
variable called post and from post we
need to access this so this is where the
repository is going to come in handy so
our repository is just a way for you to
manipulate and access your entity for
example if you want to get all the posts
that you have you're not gonna go and do
for each post in my entity or whatever
you're just gonna call it the post
repository and you're going to ask it to
give me all the values that I have in my
entity my post entity and to access that
you have two ways you can either please
come here and use dependency injection
and auto wiring you can do post
repository like this and do post
repository and we can just go ahead and
do post use that value that we just
inserted and we find our fine art is
going to get you all the values we have
some functions like right there we have
find which takes the ID if you want to
find just one we're gonna use that in
the second action that we were just kind
of creating this play the post and we
have find one by is going to find you
one thing one record by something for
example you wanna search by the title
you can use find one biting title we can
search I'm gonna see that in second to
get to it and we have fine polish which
is going to get all the records that we
have in the database and we are fine by
which is this similar to find one but
it's not going to find in just one if I
want to find you by the title or
something but it's going to be
all the records you have like ten it's
going to be 210 find one pi is going to
get you only one okay so let's go ahead
and use mine on and of course what we
want to do is want to update that to get
rid of them that's just you don't
necessarily need to update the dog it's
not necessarily the necessarily the only
necessary thing is this route right here
so this is necessary this documentation
spot is not so how do we know what type
of posts that we have right now so let's
go ahead and dump this and see what we
got sort of stump D posts and let's see
that rug so as I said who route is this
one that we have right here so slash
boats slash nothing so let's go ahead
and get rid of create and see what we're
gonna get indeed we got a post so this
is just coming from the view that were
just creating you don't have to worry
about it we create to the controller it
creating this fancy to your class but we
have our post right here as you can see
it's an array of boats but since we have
only one post it's going to be me just
an array of form value so let's go ahead
and create another one it's just called
the create as you can see a post was
created let's go back to my index page
as you can see we have two posts so it's
going to get us all the posts the post
that we have now this is great by how do
we display is right here for the user so
the user can see in a table or something
let's go back to our controller as we
see we have that view so what we're
gonna do is we're gonna get rid of this
and that is a pointer here I'm gonna
need the array because I'm gonna pass
these posts all right here so what I'm
gonna do is I'm gonna give it ki compost
and posts like this which is this
variable Y - so I can just get rid of
this where I can't I don't need it and
now this is going to transfer all the
posts that I have right here to my view
which is inside post / in the
exploration and so let's go take a look
at that post
index dot HTML as you can see we have a
bunch of stuff so what I'm gonna do is
I'm gonna remove everything so that you
don't get confused and we can start from
scratch the first thing we're gonna do
is we're going to extend the page dot
HTML web link so the left card base
quick now that we have done that we can
go ahead and put everything in our book
so we're going to do a blog body and
we're gonna end the blog and everything
that we're gonna do is going to mean
words now one thing that I forget to
mention it is that you can even since
this is only page fear you can even dump
stuff in into it so we can do posts like
this and if i refresh this I'm gonna get
a dump as you can see right here it's
dumping that they advertise that I have
now that is not looking good so what we
need to do is I'm gonna need to create
some sort of a table to display all my
values and how I'm gonna do that I'm
gonna start using some functions all
Twigg
so the first one I'm gonna use so you
know what let's each one is obviously
edge to this post and go what I'm gonna
do is I'm gonna use a table to display
all the stuff so let's in table and
let's give it some boots
[Music]
we're gonna use to head which is going
to give us B head so the first thing I'm
gonna do is display the ID even though
we don't necessarily need that second
now cuz get to be important Scott which
is the body first thing we're gonna do
is we need to go to our row and we need
to be and the first all we're gonna do
is we're gonna explain an idea right
here now this row is going to be
repeated several times so this needs to
be within before in true let's go ahead
and see how that works so quick
and as you can see it as much either for
each is just have this for user in usage
which looks like a for each and behaves
but before Easter let's go ahead and use
that see it this is what I'm talking
about so let's go ahead and do that so
we're gonna use these syntax to to do
something we're not clearing it or we
are not displaying some value that we
are actually writing syntax so we're
gonna do for post and post so for each
post the inside our post our posts that
we send from here we want to display
those that we want to end the block
obviously we want to end default for for
loop so we're gonna go can we have
everything ready so how do we display
the ID easy post is just an object so
what we're going to do is we're going to
be post ID and that is going to give us
create ID of that post the second thing
is the title so let's do post title now
let's go ahead and see what we gotta get
and this and I'm gonna refresh this and
as you can see we have a list of all
posts and we have the ID which is one
and two and title into this so this is
getting me whatever I have in my
database now I want to add two things
just to make it prettier so I want to
have something to so I'm gonna create a
link but I'm gonna click or actually
let's just make this clicker so whenever
I click this it's going to take me to a
page that is going to display this post
for me so what we're gonna do is we're
gonna change this a little bit so we're
gonna do is we're gonna add just remove
that I'm gonna add a trip link and I'm
gonna use just like before the plant
function I'm gonna I'm gonna give it the
name now we don't have that yet so what
we're gonna do is we're gonna jump to
our post controller and I'm gonna create
a function called display which is going
to oldest college show doesn't matter
which is going to show the funk to show
me the post that I'm asking for
Campos showed and this is going to read
John so let's do that right now we turn
you're probably getting familiar with
this by now so we're going to do this
renter and we get a regular something
we're gonna render something from the
post we're gonna render view called
another click okay we're gonna need to
pass something to that we're gonna need
to pass it a post but you are asking for
so we're gonna do that post like that
and post so let me just put a comma new
so I don't forget about that get wait
all right so we have that now what we
need to do is we need to get post first
thing we got to do is we need to set up
the route so let's use that got a good
route this by now so we're gonna do
slash so this is within slash post we're
gonna do slash show but we don't know
which one we want show so we wanna pass
the ID of that claim that you are trying
to view so what we're going to do is
we're going to use the same syntax as
before doing an address and ID as a
parameter we're gonna do idea like that
and the second thing we need to pass is
the name of that action this is going to
be show now as I said this is where then
everything is protected
oh so this is going to be post dot show
okay so how do we access this idea right
here well I showed you one way which is
to use the request but using the request
is overkill in this case one thing that
you can do is just press the ID like
this and it's going to work obviously
let me show you that in action so let's
do post and you can do post equal so as
I said you need the entity manager at
this point only in you need the
repository so let's take the repository
for example post for story and this to
post to post and you can do this post
post for story and you can use fun
because we are passing with the ID so if
we pass the ID like this let's go ahead
and dump and see what we're gonna get so
let's get post that and I'm gonna die it
right
that because I don't have this view
created yet so what we're gonna do is
we're gonna jump and see if that is
going to work so I'm gonna go show slash
the idea now let's not just it this way
let's actually go ahead and finish this
up so what we're going to do is we're
going to go back to our boat slash index
dot HTML twig and we need to give it the
pen now event is going to be post dot
show now we need to pass it a parameter
which is the post ID how we do that easy
just like before we gonna class
something that looks like a JavaScript
object we're gonna give it an ID this
name needs to be identical to the name
that you entered in your route right
here so we're gonna do ID and we're
gonna give it the post ID how do we
wanna get how we gonna get that we have
it right here so let's just build post
dogs ID and we need to give it the title
so it's just cool just to post the title
and is all we need to do to be the
proper views keys if i refresh this I'm
gonna see these are all going to be
actual links if I click on this it's
gonna take me to show one which is
giving me outside now this is not gonna
be happy actually these combs we have
fun I go back and I click on the second
one and I see the ID is 2 so it's two
different things now this is great as
you can see this using this in our post
controller is nice but we can even get
rid of this line lightning even get rid
of all these words here one thing that
you can do is we can use something
called the program converter it's pretty
simple converter is the name of the
thing but you can just go ahead and do
something like most folks just like to
that if you inject this post right here
it's going to get that ID and it's going
to look for that post in the post entity
and is going to give you that if it
cannot find it is going to do going out
let's go ahead and see if that is going
to work we gotta get in same result as
you can see why it's weird it's the item
2 let's go back click the first one it
is
so that's pretty amazing you can use
whatever value you want to search by
okay but if this one has to be within
the the entity's subsoil one search by
losing the title I can do that so we
have this stuff ready let's go ahead and
create this view that we need yeah
so post let's go ahead and create this
one this will show from HTML twig and
just like before I am going to extend
the base layout so stands quick and
let's put everything inside it body body
so we're gonna do block body and we're
gonna end this blog and let's just do
something like an h1 and you know just
so this proposed title let's go ahead
and see let's refresh this as you can
see this is going to be a title we have
that everything is working fine and as
expected
now we done we've done some basic
interaction with the database we can go
ahead and let's actually you know what
let's get let's get this database
wait so we created something that we
don't - it's going to help us create
we're still gonna use forms this is not
okay we are going to change this to use
some forms and we actually can go now
and let's create a remove function
before we and B so we can do a public
function let's call this remove and just
like before we need to set our route for
this so this is going to be robbed of
slash feet so if like that and it's
going to need what what is going to the
link so we need the ID of people start
we are going to believe let's give it a
name to it and just like before I'm not
gonna pass the ID and look for it
finally I'm just gonna inject right here
and we made the entity manager to be
able to interact with the database and
remove this so what we gonna do is we're
gonna do the M
guilt gotcha and let's get the identity
manager to just get manager now we have
access to that what we can do is just be
entity manager we can call the anymore
function and we can give it the object
that we want to pasture just like
persisting units basically imposed or
the object that you are trying to remove
to a persist new mode works the same
thing Newton you need to pass the beam
of the object that you are trying to
remove now just like before it's not
going to work like yes you need to call
flush after that and last thing you need
to do is just call so basically after
absolutely moving something there is no
way to point to redirect the user unless
you accept the index page so that's what
I'm gonna do right now
now redirect in a user in Symphony is
simple it's actually the same thing as
so basically each action needs to return
a response and the redirect in synchrony
is a response so let me show you how you
can redirect user within the controller
all you have to do is return I'm gonna
use this redirect which is a function
that is coming to from this abstract
controller so I'm gonna redirect to
something now I need to generate a URL
to to be able to go to redirect to that
route so we can use another function
called this generate URL and this takes
the route name so what we're gonna pass
is the post both index and the post dot
index is the name that we have right
here so it's going to redirect this
place and we don't have any parameters
whatsoever so let's go ahead and see if
this is going to work let's go to okay
so you know what I think it's pretty
much easy to go just to the index to the
post index and add or remove link right
here so let's go ahead and do that I'm
going to add another claim our wife its
actions and right here let's remove that
so let's create a link that is going to
remove that so we are gonna do so I'm
doing something a very dangerous
to send that via post via get so we
don't want to have your access to access
your beliefs your delete method actions
using get because once you Google starts
crawling in your website everything will
be both that what you want to do is
change the method I'm not going to do
that just to save some time that's
something that is not necessarily
Symphony theme but it's like a web where
you know web development pain so let's
just go ahead and keep this in so I'm
gonna call postcode delete and I want to
passively post ID so let's get it that
same notation as before post doc ID and
let's call this delete this post expect
expected name our number that's
obviously because I used let's refresh
again as you can see we have the delete
which is going to remove that at least
that smart so if I click on the lid is
going to remove this and redirect me
back to this same page I'm going to do
that as you can see it has removed that
now we don't have any feed expect this
that it's it's minus one record so what
we're going to do is let's actually go
ahead and create another one okay you
know what we can actually go ahead and
do something really nice which is going
to copy she's going to be copying this
and put it inside the create function so
inside out create function I'm gonna
instead of returning response I'm gonna
just play sports criteria and it's going
to do the same thing if I go to create
it's going to redirect me right away now
I want to display some sort of a message
when I delete something and there's
something inside symphony called
flashed messages so I'm gonna do that
for the remove but you can just go ahead
and do that like you can call this add
flash and add flush is just a function
that texture
obsession to add a message that is going
to be displayed just for one time one
single time the first thing is going to
be a string which is the type or it can
be and there anything I'm gonna do
success and I've gotta call this success
the second thing is the message that you
want to display and I'm gonna call this
the post and that's all you have to do
to display this message now you need to
go to the view I'm gonna go to my post
slash index of HTML and I'm gonna have
to display this somewhere so what I'm
gonna do is I'm gonna go ahead and just
symphony inside our view really just to
iterate through all the stuff that we
have inside talking about so we just
kind of caught me this and basically
what this is going to do it's going to
iterate through all the flesh messages
that we have but the name must be
identical to this one that we used right
here so I used success I need to change
this from roadies to success and the
message is going to be the same so this
is all you have to do right now let's go
ahead and see if that is going to work
so let's go back to this page and we go
we are going try to the needs fourth
post
let's click delete and as you can see
the post was removed if i refresh this
as you can see it's not going to work
now
I was expecting alert alert alert
success let's try to remove this and as
you can see post was refresh that's not
going to be there anymore so that's how
you use you use flash messages now as
you remember everything is static so
when I called create is just going to
create something that is hard-coded now
I want to be able to add this manually
and the way to do that it is we're gonna
start using forms and that's usually
what you use to insert some data so
let's go ahead and start talking about
forms so you can have two types of forms
in your application you can have forms
that that are related to a class
directly and you can even have forms
that are not not mapped to anything for
example like like a login page or
something like that so let's go ahead
and see in the console and see what we
have available for the Met command so
we're gonna do the HP pin slash console
and we're gonna do make and we're gonna
use so let's just do make so there's
something if you do make like this it's
gonna give you all the available
commands within them that namespace so
for example you're gonna see that we
have make form let's go ahead and use
that let's go make form and let's say to
return key as you can see it's gonna ask
you to install form applying data so
let's go ahead and do that so we need
the form component and the validation
component but let's go ahead and start
those just get a copy in place but
alright so this is quite embarrassing
for Symphony as you can see we have a
bug in the latest version and this bug
is not something that I didn't discover
myself I'm not gonna open issue
obviously somebody has already done that
now as you can see the solution to this
is to add this requirement to our
component JSON right so let's go ahead
and do it and see if it's going to work
and where's my phpstorm
so this is not something related to
symphony should never get something like
that so let's go ahead and do compose
about JSON and by the way this is about
probably gonna be fixed in like so
so in the days ago so it's only been
fixed or something I don't know let's go
ahead and add that somewhere okay let's
add that matter what I'm gonna do is I'm
gonna do composer update see what's
going to happen alright as you can see
that takes a is absolutely working so
thanks to this guy thanks to let's see
so get more Oh Georgia Mirage close but
yes so this is the beauty of the
community of Symphony Waits
it's working like twenty to twenty four
seventy days or no 24/7 they are not
even that means but they are working
hard to fix every single problem in it
was in your club so let's go ahead and
move on with our life let's go ahead and
refresh this as you can see it is
working so what I was doing so just
close this yeah so we were talking about
forms now let's go back and let's do
page P then it means there's console
we're gonna deformed it lets to make
form and let's click enter as you can
see it's gonna ask me to install these
stuff let's go ahead and do that once
then is done we're gonna go back and
we're gonna run the command again so
let's go ahead and do make form as you
can see it's gonna ask me for for the
class that is going to be used so the
name that is going to be used for that
so one thing that you can do is so let's
call this post-op course I'd like that
enter and I say see is gonna ask you for
the entity or the model class that is
going to be a bit used to to bound to
this wall so this one will be bound to
some class and that class what is going
to be is in our case we have posts let's
go ahead and enter that post as you can
see we have green so let's go ahead and
take in slide it's our C form we have a
form so let's go ahead and see that as
you can see we have a new folder we
gonna take a look at the post type and
this is what is going to be within that
so we have a bunch of stuff now as you
can see the most important part at this
point is the resolver which sets the
defaults to their class which is post
class it says that the data class for
this is forum in steam post so it's
going to be used up now as you can see
it's already texted that I have this
this title field to column in my entity
so it's going to yet to be adding that
in my builder so this is how you add
fields to your form how do you saw you
add inputs to your form you just have to
build or add so let's go ahead and see
how we can use this let's go back to our
post controller and within our create so
let's go we'll go back to create
function as you can see we need to get
rid of this and we need to have a form
so how we can create the form is pretty
easy now we need some some form so we
need an route to display the form so
let's go ahead and render form or under
view
I'm not each other I'm saying at this
point let's go do return this random
post and so it's and we're gonna need to
pass some parameters so first let's go
ahead and create the form so I'm gonna
get rid of this and I'm gonna do before
so I'm gonna do form equals I'm gonna
call this and we have two options we
have creates form and we have creates
form builder now you want to create for
create context one one or actually takes
two parameters the first one is the form
that you know that I want to use in my
case is the ball strike which is within
app form this namespace I'm going to
enter and I'm going to class so I can
press the whole qualifying namespace for
that quest the second thing is the data
or the object that this is going to be
bound to so this post object is going to
be filled with the data that is going to
come from this ball
once we submit so you can either pass
null if you don't have any or you can
use
or the object that you have so we have
post we're gonna use that now this is
going to create a forum for us let's go
ahead and pass that forum to you so as
usual we gonna do that and we're gonna
go form like that now this is not going
to work as I manager in second but first
let's go ahead and create this view so
I'm gonna copy the name I'm gonna go to
post create HTML and let's do the usual
stuff let's extend it extends being
based on HTML twig and let's go ahead
and add okay so we have that now let's
go ahead and blend it our form so
rendering form is pretty easy all you
have to do is call this called default
function and pass it the name of the
form so this is the name of the form
that is coming from here let's go ahead
and see what this is going to give us so
let's go to our browser and let's say to
be create or out as you can see we have
some sort of an error so I just insert
yeah that's because I've made a mistake
so I need to get rid of this stuff
because we shouldn't be inserting right
now because we've done time in there so
that's that's way let's go ahead and
refresh this as you can see arguments
want us to reform renderer and the block
must be instance of all this stuff now
this error seems vague and abstract you
don't understand with this now basically
what it means inside this we created a
form but we want to create the view for
the form so that we can pass it to our
fueling users so what you need to do is
on this value on this form variable that
we have we need to called creates view
and that is the going to create a view
and that is going to create the form a
proper form that is going to use as you
can see we have that right here so a
couple of things that we need so we have
the title we need to submit button that
we have two options you can either are
the edits on the view right on the view
right here or or you can add it on
type itself so I like using I like
sometimes items in the type of depends
so what I'm gonna do is I'm just gonna
call something I'm gonna add this one
I'm gonna call it safe the first
parameter is the name the second one is
the type so type in this case is
submitted
it's like it's just type and the name
space is inside symfony components form
called type I know you can see but its
core type so it's just gone show you
that it's right here so it's symfony
components for an extension called
type submit' so that is the last thing
that you wanna pass is some options that
you can pass to your see you now it's an
array of options now let me just show
you what i mean i refresh this as you
can see everything is now this is what
we're going to do something in twig so
into it we want to tell that our entire
application is based on bootstrap so i
want to whatever you see will form an
input or something or a label i want you
to use some bootstrap styling on that so
it's pretty easy to use that so instead
of just having to customize everything
in us-born group form controller and
everything symphony comes with a
predefined thing if I go to my config in
my packages in Twigg torciano you can
see that I have some options one thing
I'm gonna add is form team and I'm gonna
ask you to use bootstrap underscore
underscore lay out dot HTML to it just
this now if I go back and refresh this
as you can see big big change this into
proper bootstrap and I didn't have to
write a single line so that is working
perfectly now let's say that I want to
apply some some custom class or ID to
this field writing so what you can do is
you can go to the type so let's go back
to the post type and in the third array
or third parameter we're gonna pass an
array and within the array we're gonna
we are
we're gonna add a key called attribute
and that attribute is the attributes
that you usually see on HTML so you just
inspect this it's pretty small on re
that can't see but as you can see the ID
and the class and all that you can
change those by using this attribute
White's here so you can change those
items let's say for example that I want
to add a pull right to this class we can
add right here so we can do that that's
good class and we can do all right so
it's kind of overwrite the existing
class what I'm going to do is I'm going
to be beating MDT and primary and I'm
gonna do all right all right let's do
that
and it says all right
it's probably something I've changed and
moodstruck for Sun Studios and the
recent excellent just sit back
yep it has changed it's called float
white today so I'm gonna do float right
and as you can see it's gonna go and
jump to that and dip so that's how you
can add custom action goods to your
field well let's say so we're gonna
enter something I'm gonna do I'm gonna
enter nothing is going to happen now
this one isn't it's being submitted but
we are not handling that so what we're
gonna do is we're gonna go back to our
controller box controller and we're
going to handle this submission of the
form now usually how you do that is
really easy you want to have two
requests right here so you need to have
your request we're gonna do form we're
gonna call handle requests just step on
correctly we're gonna call handle the
request which is going to handle a
request for us and it's going to get all
the specific values that are that I need
and what we can do is we can check in
form submit it the phone is submitted
then I want to do some stuff that stuff
would be I want to get the entity
manager and I want to persist something
too in database okay so fair enough we
have that so if the phone is submitted
let's see what we have and our post
object okay so let's go ahead and add
something let's do camp let's enter as
you can see I'm gonna get the post with
the ID no that's because it has not
persisted the database yet but we get
these items can now at this point I want
to point something out there as you can
see this dump is pretty ugly at the top
and it's messing with your design one
thing you can do is you can install this
profiler
and as you can see we have this web
profile abundant let's go ahead and
install that actually is unsolvable that
seems pretty here so let's go ahead and
do like usual composure require filer
which is going to use simple flex to
install these this bundle force
all right so it's done as you can see
and the profiler if I go back to I'm
gonna go back to my application let's
refresh
yeah just resend it doesn't matter
as you can see something has changed so
we have this profiler bar at the bottom
but I'm not really sure why it's much
it's not displaying the dump at that
plate so I was actually expecting to get
this dump at the bottom so is it this
one or did I make a mistake that I
should I install this one I'm just going
to try it or not by the way you can even
use rec if you want to extend or
required just use that you want to so it
says that it's already installed the web
profiler bonded so I'm not really sure
if that is going to fix it yeah nothing
to install or update it seems like we
get it just gonna have to do with the
ugly design but it usually should show
you a bull's eye icon right here
if you hover over that you're gonna get
all the times that you've got it seems
like it's not working right now so let's
not bother with that so we have our form
we have our post so what we need to do
right now is just persist this to the
database so let me just change that I do
have two jars I'm gonna say and what we
need to do right now is just put the
code back so as you can see just gonna
persist we have our entity manager we're
gonna persist and flush them get rid of
this message and what we want to do
actually persist is we want to return
obviously so let's return and that's
redirect to somewhere out that route
would be let's generate the work first
that is going to be closed so if I go
ahead and save this
then it's safe as you can see it's going
to be added free quad-cam and so
everything at this point is working now
everything is working I
that's I think that's pretty much it for
forum so this is the basic functionality
of fun this is what you you need to know
in order to make your first forum and
make everything working now I think
we're gonna move to so you can add some
validation if you want to obviously I
haven't spoken about validation yet so I
haven't talked about it so you can add
some validation inside your entity for
example I go to this I can import I
search so it's constraints make sure
it's going to transfer its friends it's
validation as assets this is what
sinking it doesn't this is what I do I
like this so I can assert but something
is going to be of a certain type for
example I do assert I can do not blank
and not equal to not know and this is
going to add some validation and once
you have some validation so for example
I do not blank if I add this one way to
check if the form is valid or not is you
can add inside our post controller when
we check if the form is submitted you
can do and look form to the second form
Hispanic but the form is valid that you
have then you can go do that it's not
valid that you don't you know you can
just stop and you can get the form
errors but doing this for get errors and
it's going to get you all the errors
that you have in the database in case
you want to display that to the user and
we want that this is this field should
be of this type and so God so you can
play here so I'm just going to get rid
of this as we don't like any validation
right now but it's you know so that you
know that we have validation insulin
into now I would like to talk about
something important which is security so
we're gonna start talking about security
before we move on to I want to get back
to doctor and talk about some other
stuff because that's like the most
important thing which is entering
database but first I want to talk about
security so I want to add two things I
want to add a login page
and I want to add a registration page
where we gonna create a new user with
new users and in symphony for that's
pretty easy so the first thing is we're
gonna create a login page
let's go ahead and do that I'm not
really sure what I'm looking at the
controller but we need to go to our
console
let's do experience - console and let's
go let's just see what commands do we
have so if I scroll to the bar to the
top actually I'm looking for the Mega
Man yeah it's right here you can see
that we have make off now make art queer
it's a god-awful indicator of of
different flavors now I'm not sure even
the first flavours means but it means
that it's going to create something that
is going to help me authenticate my
users into the applications now we're
going to notice that we have make off
before you can make up use make up you
will need to have a user entity our user
entity is the user if the entity where
all universes will be stored now if I
just go ahead and try to run that
command I'm going to make art you're
going to see that it's going to ask me
for the exterior components let's go
ahead and install that
all right so we have that can start
let's go ahead and run the same command
again PHP this much console make off I'm
gonna hit enter as you can see it's
gonna it's gonna tell me what style of
autumn came to do you want we want to
login for all you want something empty
that you can customize later so I want
to take the easy route and I'm gonna say
that I want to login form Authenticator
Sonos play:1
it's gonna tell me the name of the
authenticated close the Authenticator
class that you want to hear just enter
some them I'm gonna do I'm gonna enter
and it's gonna ask me for the controller
class so I'm just gonna do security
controller and hit enter it's gonna ask
me for the user class that you want to
authenticate now at this point I have
nothing and that's what I mean by to you
but you need to have a user entity
before we do that so one thing that
comes with Symphony is by the way I
pressed control see I just stopped
everything that I was doing so what I'm
gonna do now is gonna do HP dance watch
console and I'm gonna do bake and I'm
gonna do make user so that is going to
help me so I'm not gonna make an entity
and call it user so I'm gonna show you
the difference when I do make user it's
going to ask me for the security class
obviously I want to know sir do you want
to start using data in the database use
induction yes I want to enter the party
man there will be unique so in this case
I'm just gonna do yeah let's go is your
night good night
and this up is going to hatch the user
password yes it's going to ask that you
go start me so it's just with it and as
you can see if we have green now a
couple of change a couple of things that
has changed we have a new entity called
user we have user to expend all stories
first but we can be to that doctrine we
have the entity those are updated
because it changed some stuff and we
have this configuration spirits about
Gamma Phi that change let's go ahead and
see what happens if you go back to our
config packages you can see that we have
security though jammin if I open that
file up you can see that some stuff that
was there that were added to it father
to this while they were not cheering for
so we have the encoders encoders as you
can see is what is going to be use to
hash your password now if I do make
entity and call it user and just try you
know create entity that way I still have
to come back to this file and add all
this stuff that I have right here but if
I make but if I use make user it's going
to add all this stuff is going to
interactively ask you for this for this
information is going to add it to
security that you have applied and you
don't even have to to worry about this
so we have the encoders as I said this
is the algorithm that is going to be
used to hash your password into the
database if you can use you can use our
Guney like this or you can use P crypt
if you want to use probably other stuff
but I'm not gonna bother with that right
now and we have the providers of the
proprietors of course for the sake of
the beginners course I'm gonna keep it
simple if you only provide that that I
have right now is the database so you
can have an in-memory you can have an
LDAP you can have whatever you want but
basically I know that most of you are
gonna be loading users from your
database so we have this provider right
here and the entity that is going to be
used is the user entity and the property
that we're going to use to actually call
our to search for that user is the
username now we gonna notice that we
have firewalls so we have def which is
something for the development
environment it's gonna allow you to add
some JSON that these are firewalls so we
have main and as you can see it says
anonymous chew which means anyone even
is it it is it's not authenticated
before because we don't have any
authentication right now we're going to
be allowed to access this now this is
going to change in second as you can see
the file structure is going to change
now one thing is access control access
control is where you want to set up some
patterns for your website for example
let's say that you have an admin
dashboard that you want only the users
with world admin to be active to be able
to access you can do you can do that
right here and the profile is something
you know these are just Patton for
example if I want to to deny access to
my entire application if you are not
authorized I can do that by just doing
this using whatever comes at
this needs to be needs to have a wrong
user and an archetypal user you need to
authenticate into the application now
you don't even need to take a look at
the entity of the user because it has
some basic stuff like a username the
roles that I was just talking about the
password and that's it and of course the
ID now let's go ahead and make our form
so let's go ahead and do PHP then slash
console to make I do that and press
ENTER as you can see it's gonna ask me
for the same stuff I want a lot
important Authenticator so I'm gonna
press R on the return key the name of
the class of the Earth Medicare I'm
gonna call it I'm gonna call it customer
and the patron the controller class
going to be sketchy controllers that's
fine with me and as you can see it bits
and stuff it created this customized
Medicare with an hour security directory
that was just created right now it's
updated the file security about Yama we
have a new controller created and we
have a new template HTML twing so finish
the redirect to do indeed yeah we're
gonna do that in a second so let's go
ahead and see what was creates for us so
of course let's take a look on the
structure as I said the security Dojima
file has changed a little bit as you can
see the guard that is going to be used
right now is this one right here this is
the automatic error that is going to be
yours is the security custom
Authenticator that we're gonna take a
look at right now so let's go ahead and
see that as you can see we have a new
folder within our SRC they have a folder
called security if I open that up you're
gonna see that we have a bunch a bunch
of stuff that you don't need to worry
about but this stuff is working now the
thing that I was telling that he was
telling me to check to do right here is
to change this on authentication success
so basically what it's telling me to do
is after the user the user successfully
authenticated where do you want to send
it where should I send you users where
do I want to redirect for example when
are we there in the user to is profile
page or to the index page over to this
dashboard or whatever so you can do that
right here and I really got a problem
with that so I'm just gonna leave it
like that so let's go ahead and
what's wrong was created for us let's
new HP okay one more thing that I forgot
obviously is the security in shorter and
as you can see we have the login around
to collect here the action so as you can
see I'm not gonna go into details but
this is the authentication notice that
you can use to get the last
authentication error and to get the
username of the person that was trying
to log in as you can see we pass that
same data back to the to the route that
was created to the view that was created
for us which is security login partition
other way and I want to take a look at
the route that was created for us or
logging so we're gonna do debug button
from the console as you can see a latex
and just a so as you can see a bunch of
stuff was added for us this is specific
so the profiler you don't have to worry
about that but one thing that you're
gonna notice is we have a new and a new
route called our plugin with the name of
our plug-in which is a super via /
logging go ahead and see what that looks
like so if I go to slash login as you
can see we get a username and a password
prompt so it's gonna ask us for that
data so whatever I enter right now it's
not going to work obviously because we
have as you see it's gonna tell me that
there was an error when it was trying to
go to the database what we have to do
and I forget to do is we need to migrate
our new user entity to the database
let's go ahead and do that absolutely
experienced our console trend schema
update and we can do dump sequel
you're gonna notice that this is we're
going to be executed it's going to
create this table user let's go ahead
and force that and as you can see one
career took effect and one query was
excluded - let's go back and I'm gonna
go back to the page and I'm gonna enter
a new set of credentials even though I'm
not going to work I'm gonna excite end
user name could not be found now as you
can see form that's because I have an
empty database now
well my empty database but an empty user
entity use of tables let's take a look
this user is pretty much empty now I can
go ahead and try to create something
manually and all that but I'm gonna take
this I'm gonna take advantage of this
situation so I can create a register
page so what I'm gonna do is I'm gonna
create a new controller I'm gonna call
it this HP pins much console and I'm
gonna do make a controller
I'm gonna call this register control
actually the registration controller
seems better relation controller so it
seems like it created that what I'm
gonna do is I'm gonna go back to my
editor I'm gonna open up registration
installer and I'm gonna create that
function so I'm just gonna call this
seems like it's a registration so I'm
just kind of closed resistor at this
point and this is going to be richest is
not making sense
I'm gonna get rid of this controller
controller name variable and I'm gonna
go ahead and start making a fun now this
is what I'm gonna show you how you can
make a form for your user
losing the inside the controller now I
actually don't recommend ever using this
but I'm just gonna show you this just
for the sake of the video so we can do
form equal space create form builder and
create form builder takes you know some
data or we be taking it can take nothing
so in this case I'm gonna what I'm gonna
do is I'm gonna add some fields so the
first field I'm gonna add is gonna be
called username I'm gonna keep this
pretty simple the second field I'm gonna
add and by the way if you don't enter
any type a second parameter type as a
which is the type is going to default to
a string to an input of type string you
know thanks so the second thing we need
is the password so I'm gonna do password
like yes and I'm gonna go ahead and this
is not going to be a password type as
you see this is a password of course
password type is going to work but we
need to values of that so we're net we
cannot actually just do password and
then repeat password after that what we
need to do is we need to use something
called
[Music]
not today so I'm gonna use the rotate it
type class and this one takes a couple
of options that I actually don't
remember so what we need to do is we
need to actually go and check the
documentation for that let's go ahead
and go get that stuff up so it's true so
I'm gonna do Symphony repeated pipe and
that should be some so as you can see
this is the type so we can specify a
type which is going to be a password
type so let's just copy that let's go
back to our editor and let's paste
that's right so we have the password
type let's not forget to import the
namespace I'm gonna import the class and
you can yeah this is something that a
lot of people behave in asking for so
what we're gonna do is we're gonna add
required to doesn't matter if you add it
or not but we need the first option to
have a level of password and the second
is to repeat transfer will confirm
possible so this is something that I've
got a lot of questions about when I made
some previous videos about this stuff
but it seems like nobody has went to
check the documentation so anyways yeah
we have that now let's go ahead and send
that form to to the actual do now before
we do that this is a create form builder
so this is form as it now is just a form
builder to get the form out of that we
need to do get form we need to call the
get form after everything so get one at
this point this is going to be a form
but when you still need to call the
create form create view on that we're
gonna do form get fuel in order to be
able to use that in the index or HTML
HTML within our registration so let's go
ahead and open that up I'm gonna get rid
of actually I'm just gonna get rid of
all this stuff let's do like we used to
do
and that's a walk and at this point I
can just go ahead and do form form
I've just spoken correctly so let's go
the form form like that and let's go
ahead and see what we missed
so at this point what I'm gonna do I
still had to actually you know handle
the farm and everything but I just want
to see this stuff working so what I'm
gonna do is I'm gonna go to my register
as you can see I have a username and a
password confirm password I still never
fun so I'm gonna go ahead and create
that I'm gonna add its doors let's cut
let's cut bricks this is going to be a
submit type and dad and we wanna do we
wanna pass some options yeah let's do
that just for the sake that says so as I
said you can pass some attributes I want
to change the class to be an array and I
can change the class by doing something
like that so BTN BTN primary and I can
say okay I want this to be success that
we have our resistant button so if we
try to do something nothing is going to
happen obviously because we still need
to handle bugs that's good form and
that's hand with a request and we don't
have any weaker so let's go ahead and
inject that our their search function so
is to request I forget to enjoy the name
space so HTTP foundation request let's
go ahead and press this flags here and
as usual we need to handle the form we
need to check is submit it so if it's
submitted if the font type is the same
post then we want to do some stuff stuff
like a good is we want to get a so we
need to do this get doctrine a skit
manager
and we want to do entitymanager we want
to persist some user that we're gonna
create in second so we're gonna go
persist and we're gonna create to do
second about that so I'm gonna do it
flush so what do we want where we are
where are we going to get this user from
now this is not going to be mapped to
any form of class to any entity that we
have because nothing have password and
and you know I repeat right so we're
gonna do is we're gonna actually I want
to show you how you can get the data
from the request and on the phone so
let's go ahead and do user user like
that the namespace is entity and that's
dump the user so I'm not going to dump
the user actually I wanted a before and
there's something because you can use to
get some data from the form to use is
data equals form get there for a spot so
dads can see what we have submitted data
so as you can see we're gonna enter some
user names and passwords and password
I'm gonna register as you can see I'm
gonna get an array of username and
password now the username is not hatched
or whatever so simplex is trying to
insert yeah so this doesn't matter so
what I'm gonna do is I'm gonna take the
username and I'm gonna tell you the
password but the password needs to be
hatched so the password needs to be
equipped and report it encoded or
created or hatch whatever you want to
call it before it's persistent into the
database so what we're gonna do is we're
gonna call something that is going to
help us do that and that then is the
password
encoder so it's actually user password
recovery professor face and passport and
cold now by the way this is why you
might be wondering why how does this
thing work this is called auto warrant
and it uses dependency injection it
knows that you are asking for this so
it's going to inject it to a function so
that you can use it so that's a simple
thing now as I said we need to actually
go ahead and save ink
the peso before can send it to the user
now how do we do that so we have access
to the user name and the password from
the data it's just an array as you can
see so what I'm gonna do first is I'm
gonna do I'm just gonna leave that I'm
going to change that to use it so what
I'm gonna do is I'm gonna be user and
I'm gonna set he gives her name so I'm
gonna set the username to the data and
then I'm gonna try to use a man combat
the second thing is deep password so
what I'm gonna do is I'm gonna do set
password and as I said I need to encode
the peso before I can use it so what I'm
gonna do is I'm gonna call the password
encode their interface and I'm gonna
call the encode password on that and as
you can see that takes two functions to
function that takes two parameters the
first one is the user that you are
trying to hash I had that right here so
I'm going to pass that the second thing
is the plain text plain text password
that you are trying to hash or encode so
what we're gonna do is we're gonna call
data I'm gonna get the password for that
and that's pretty much all we need to do
to be able to hash the user now I'm
going to put one small die I'm not gonna
die I'm just gonna you know what let's
actually use it's just three there right
to the login page without any messages
but now that we know how to use that so
let's go to this either red and this is
going to take us to be and that is going
to take us to me page right after we
dump right after the new user so let's
go ahead and see if that is going to
work so I'm gonna go back to the rear so
tooth page I'm gonna create a user name
with the name pass with a name admin I'm
gonna call the I'm gonna and at least
you six
and I'm gonna enjoy sister so as you can
see it's I'm a login page and let's see
if we have a UID user so I'm gonna
browse it seems like I have a new user I
don't have any rods right now that's
something that we're gonna I'm gonna
discuss in a second but you can see we
have some password right here it's it's
it's a password but there's not much 6
zeros that I entered that's what gets
hashed now let's go ahead and try to
access to log into our application so
I'm gonna do six zeros and I'm gonna hit
sign in as you can see I am sonicated
anonymously so logged in as anon so I'm
gonna excite in and as you can see I
need to provide a redirect inside its
function now this is not an actual error
this is just something that I was
talking about that I forget to do like
it's asking me to handle this right here
so we can do something we can like I
don't know you can do whatever you want
I'm not gonna bother with this right now
you can redirect if you want to so let's
see if Murray died right so is the
constructor do we have a you are
generator interface yeah since that we
have that so we can use that but do we
have any redirects that would steal it
stuck we don't have let's just write
that so I'm gonna do return you redirect
response now this needs to be with our
work response it's just something that
in yours for my response so we're gonna
use that and we need to generate a URL
so for example it seems like we already
have that I just see it so let's go
ahead and steal this and though where do
we want to go index right after we do
that so I'm gonna refresh as you can see
I'm going to resend and it's going to
redirect me to that let's go ahead now
and see what we have right here as you
can see I'm logged in as an admin I'm no
longer nobody I'm an admin you know a
user I'm authentic Aidid through this
firewall which has the name bang now we
have done most of the stuff now one
thing that I want to do before we end up
with security stuff now I'm not going to
talk about obviously I'm not gonna talk
about security a lot because that's a
fast and a very big topic so what I'm
gonna do is I'm gonna keep it really
simple we have a login page we have we
have a registration page what I wanted
is when deny access to some places so
what you can do as you can see we don't
have anywhere and we can tap a logout
URL anywhere so what I want to do it is
let's go ahead and I'm going to show you
that in the button patients will go in
for all right I finally found it is
inside this security page on this
Anthony talks as you can see logging out
is pretty simple
all you have to do is put this under the
main firewall that you have log out and
the path is going to be back so yeah of
course you have to create that box so
let me just go ahead go back to the
security go to M file and under the
firewall I'm gonna do this after that
I'm gonna put the log out right here and
is invitation as you can see it says log
out now this name is not exist yet so
what I'm gonna do is I'm going to go to
security thought security controller and
I'm gonna create that right - so I'm
gonna do a public function log out and
this does not take anything and it give
me empty nobody's going to care about
that so I'm gonna do that and I'm gonna
call this out and it's change this to
log out to match the name that we just
injured what yeah so if I go back to my
tournament and I try to debug the router
as you can see I have a logout route
right here and what I can do right now
is I can go back to my layout for
example based on HTML tweak now one
thing that you're going to notice them
just hate when I start doing this so
let's just go and do this first make you
float right here right let's try so we
gonna generate a URL so this must not
have and grantors but we gonna do
[Music]
without gout let's go ahead and refresh
our page and see what we're gonna get as
we see we have a logout right here now
if I go back to my profiler as you can
see it right after I add that log out
log out controller or action I'm gonna
see that I way like that we have access
to that so we can either click on this
or that now as you can see I still have
access if I go back to post slash index
I still have access to this
I want to deny access since I don't want
the user to be authenticated I want to
use it to me plugged in learner to be
able to see this page so what we gonna
do is we're gonna go back to our
security go Tiamo and we're gonna start
taking advantage of the access control
now what we're gonna do is we need to
set up two things that the first thing
is the login page so the login page
needs to be accessed by people who are
not authenticated so what you need to do
is roles need to change that to ace or
client to gated anonymously right so the
login page you don't have to be logged
in to be able to log in so there's not
making sense so you have to set this
before actually set in the wild card now
this is the this is very important this
will not work that's this will work okay
so pay attention to me order of the
tuning patterns so let's go ahead and
see if that is going to work so I am not
logged in as you can see I am anonymous
they logged in so I'm gonna refresh this
as you can see it's gonna take me to the
login page it's gonna ask you to sign in
let's go ahead and sign in and as you
can see I am NOT authenticated and I can
see my page so I can do whatever I want
right now and this is going to be a
title so it seems like that is almost
yeah let's do one more thing so okay so
that means
so we can do one more thing so within
our application let's say that evenly so
let's say that the login page as we see
the login page has access to this log
out now this logout actually makes no
sense why do i why can I log out tonight
I will be loved up to this let's add
inside our basically HTML condition that
is going to check if the user is logged
in or not before we can actually display
it so let's go to our base dot HTML or
twig and where's that based on Easter
number 20 and they log out we don't want
to do this unless we are not logged in
so there are a couple of ways that you
can check if you're all locked in so
let's go back and see some of the stuff
in the documentation so as you can see
you can check if the user is granted
using that so and we have something
indoor is granted in the template so for
example if you want to check the road of
the user so you can do that so just copy
that line basically this is going to
check if the user is an admin oh if it's
a user it's not going to display this
but that's not what I want I want to
check if the user is logged in so what I
can do is check if the user is
authenticated but anonymously but fully
the user is fully authenticated then I
want to display this bug this bug out
front let's go ahead and see if that is
going to work so on that log then as you
see I'm anonymously locked then I have
log out so I'm going to refresh as you
can see it's gone so let's go ahead and
see if it is going to be there when I
log in what stance as you can see I have
log out and that is working perfectly
fine so that is what I want oh that's
what I wanted to cover basically for
security that now one more thing I'm
gonna do before I move on actually not
yes so that's basically all I wanted to
cover security at this point what we
gonna do right now is I want
back to doctrine and induction I want to
explain some stuff so basically as I
said our post has absolutely nothing
right now except for a title and nothing
else so what I'm gonna do is I'm gonna
actually I want to actually change that
too so I want each each post to have an
image related to it so what we gonna do
maybe a category as well so what we're
gonna do is I'm gonna show you how you
can add an image and then we're gonna
discuss how we can actually we're gonna
create a relationship so this is
something that is quite related to file
uploads which is a common topic between
everybody wants images because why not
so what we're gonna do is we're going to
change our stuff a little bit so we're
gonna change our entity so what we're
going to do is we're going to go and add
to our poster page P we're gonna add the
image that we are trying to access but
we are trying to upload so we need to
save that somewhere now in our database
we're not gonna save the actual image
we're just gonna save the path to the
image we want to say that so what we're
gonna do is we're gonna call this image
like that I'm gonna give it a couple of
stuff I want this to be an hour and
column is going to be that column is
going to be of type string the length is
going to be and that's all I need to do
now as I said each popteen is together
in a setting so what I need to do now is
I need to create together since Eric now
I can go ahead and create and create
them manually but let's say that I just
created ten new properties what you want
to do is you want to take advantage of
the console again so if I do catch creep
bin slash console and I do make entity
like this link entity if I add the flag
regenerate after that it's going to go
through all these and try to regenerate
anything is you know if anything is
missing as you can see it's kinda askew
from the namespace to regenerate I want
to generate to regenerate all the
entities what it's going to do is going
to leave the ones that are not touched
untouched so it's not gonna touch
anything very small support to touch but
it's going to update whatever it needs
so if I go
to post the page we are gonna see the
image now has and get in a set and so we
have some answers for that now let's go
ahead and see how we can actually handle
the file upload now before we do that we
need to go back to our form
so our post form and we need to add
something that is going to upload the
file for us we need a field where we can
select the file that we're trying to
upload so we're gonna do is we're gonna
add an image and that image is notice
how the same name that I have liked here
is the same that I have liked here but
I'm not gonna use that actually as I
said this is going to be a 5-time so
fine which is inside the same symfony
component form extensions core site and
I'm gonna do a class and after that so
let me just show you one thing so if I
just leave it like like this and I go
back slash create
it's post / as we see I'm gonna get the
image and everything is working fine but
if I change the name so let's say that
this is one kind of attachment instead
of image if I do that you gotta get that
these are the attachment model property
Martin method get attachment attachment
is attachment whatever is inside this so
you might you might actually want to be
something like this where you have a
different name in your phone than the
one that you might use in your entity so
what you want to do in that case is you
want to tell it that this field right
here is not related to anything in the
database or entity so what you want to
do is you wanna pass in the array and we
need that you gonna pass back through
cause actually I'm not really sure if
it's mapped or multiply and I'm gonna
try that
oh that's and as you can see it is
working its map set to false and it's
working because this is not going to do
persist this attachment here there's not
going to be vs. anywhere or led to our
entity so we can select a file and do
whatever but it's not going to work now
that's showing anything so what we need
to do right now is we need to go back to
our controller in handedly file upload
so let's go back to our host controller
and within this we have some stuff so
let's go in what I want to do is I wanna
dump got the form but I want to dump the
request I want to check the fly so
inside the request we have a files
property back or an array that is going
to be filled with pies that are sent
from the client so that's what I want to
take a look at I'm gonna enter something
and I'm gonna choose some five I'm gonna
hit save and as you can see I'm gonna
get a file bag so do not worry about
this the image still needs value you
know that in second as you can see the
file back around to his post
this is the form and see within that
uniform actually this so within that we
have the attachment which is the file
that we are looking for so what we're
going to do to get access to that is
from files we need to do get get what
same name that we used absolutely find
the post type we need to get the same
name that we use right here so we're
gonna get attachment and I'm gonna so
I'm gonna save that in a five save mr.
space type in and what I want to do is I
want to check if I have a fight before I
uploaded okay
now if I have a fight if the user
actually sent a file while I run it who
the case I want to save that fight
somewhere now before you can save that
fight we actually need a fine name for
that now I cannot just I can just go
ahead and use the same file name that
the user sent but that is what we gonna
cause some problems and conflict it to
images have the same at the same name so
what I'm gonna do is I'm actually gonna
generate a unique file name for each of
my five so what I'm gonna do is I'm
gonna create this particle this variable
called fine name and I'm gonna use chem
d5 and I'm gonna combine it with unique
ID to generate some some unique fine
name for my for my phone I'm gonna
concatenate this with something which is
the extension so this is going to be the
fine name plus the extension so what I'm
gonna do is I'm gonna call five and I'm
gonna go get so it seems like one thing
about datastore is that it can help you
if you add the proper types to the five
other comments so I can do uploaded five
that is going to give me some functions
it gets client extension which I'm gonna
use to get the line extension now we
have a fine name what we need to do next
is we need to actually move this file to
somewhere so it's not being safe
anywhere so what I want to do is I want
to save this inside my public folder
which is the public which is the folder
that is publicly access to anyone that
is visiting my site so what I'm gonna do
is I'm gonna actually each group it is
five I need to know this file somewhere
so I'm gonna call the move and the move
takes two parameters the fur
as you're gonna see is the directory
where I want to move the file and the
second thing is the fine name
so this economy we're gonna do it this
is to move the second thing is going to
be the file name so we need to give it a
fine name
Thanks now how do we get a target their
target directory now we can just go
ahead and hard code this way too if you
want to but I'm not really a big fan of
that's what I'm gonna do is I'm gonna go
back to my config files
I'm gonna look for framework or Tiamo
and as you can see ya services go teamö
we have some parameters that you can be
fine you have this local which is Center
relates translation which is not
something we're gonna cover in this
video but we we can create our own so
what I'm gonna do is I'm gonna create
someone called uploads directory and
this can take what everybody you want to
give now what I'm gonna do is I'm gonna
tell it to give me the project directory
that I'm currently can and I want you to
concatenate that with public slash
uploads and this means that all my files
that my uploads are going to be stored
in the public folder in the uploads to
me that I just mentioned watch here so
what I'm gonna do is I'm gonna go back
to my post controller and I need some
way to get that value and of course
there is a way to get that value what
I'm gonna do is since I mean inside the
controller I can do this kids
parameter like just and I can give it
the name and the name needs to be the
same as the one that I use right here so
I'm gonna do that space yeah
that's pretty much all we need to do to
move the file now we move the file we
need to do one more thing we need to
actually persist we need to actually set
a file name to our database so that
would be safe so what we're gonna do is
we're gonna do post sit image and we're
gonna do final and we have access to
that right wait so what we're gonna do
next is it seems like this is going to
work so you know what the best way to
check if this is going to work it is by
actually trying it so let's go ahead and
get rid of all this done but I have it
sounds like I have nothing so listen you
just go back right here what I'm gonna
do is I'm gonna do post with image and
the attachment we gonna select is just
some let's let's do this I'm gonna hit
save and as you can see it's it's
telling me that exception and no so it
said that it does not know what an image
piece that's because I once again forgot
to migrate my changes to the database so
let's go to HB bin slash console and
that's without trend schema updates
forest I'm not going to dump because I
know it's going to do as you can see one
query was executed so I'm gonna go back
what I'm gonna do is I'm gonna hit ctrl
R and I'm gonna reset all the data that
I just sent and I have the same error so
it's a better image cannot you know made
a mistake somewhere so just think about
this for a second I'm gonna try to move
these probably it's not even going into
this condition right here so I'm gonna
do is I'm gonna do that and I'm gonna
just resend again just so it seems like
we don't have a file so what I'm gonna
do is I'm going to be done
yeah that's obviously whatever I messed
this up so what I need to do is I
actually need to get post and post is an
array and I need to get the attached I
believe so so let's just go ahead
that is going to work so let's go back
to connect and let's do the attachment
is going to be somewhere in nature save
and it did something so it did something
we have something let's go ahead and see
if the file is uploaded just by in so
where's the public folder it seems like
it's created a new uploads by artery and
within that we have the finder which is
ask now it's working properly let's take
a look at the database in our post as
you can see we have the image file name
right here so how do we display that so
what we're gonna do is inside here
actually not here so when we try to view
an image when we shown in when we show
up close I want to display the image as
well so let's go ahead and do that now
we don't need to change anything in our
controllers whatsoever what we need to
do is we need to go to our templates in
the post show because we already have
two access to the post what we're gonna
do is we're gonna add the image and we
want to put SRC right here so if I do
just close the image I'm gonna see it's
not going to give us anything because if
I take a look at this it's gonna give me
so I'm sorry for the relatively small
text as you can see I have an image but
this is not the correct directory that I
need I need to get that from the slash
uploads slash finally so how to do that
we can concatenate right here by doing
something like this so we're gonna go up
loads slash and I'm gonna use slash why
not and I'm gonna concatenate this using
the - alright tilt or I think Chris is
up tilt just going to concatenate these
to it for me so I'm gonna go back and
refresh as you can see I'm gonna get my
image so this is how we can get image
now I want to create a category for each
post how do we do that it's very easy
what we're gonna do is we're gonna
create an entity so we're gonna start
talking about relationships right now
we're gonna go and cover the most basic
relationship that you can imagine and
you can actually go ahead and you know
you can start experimenting with that if
you want to do something more complicate
so what we're gonna do as I said we're
gonna use categories for each of our
popes so we're going to do it is we're
gonna do generator MTT it's gonna become
category so let's go Pippin /
console and make an engine and we're
gonna call this category obviously so
let's go category and we want to add
some prompts which the first one is
going to be I don't know it's gonna be
name yeah let's just do name and let's
just keep it name for now and that's all
we're gonna need as you can see we have
category dot PHP and we have HP how can
we create the relationship between those
now each now the relationship that we're
gonna create is gonna be called a many
to one and a one to many relationship
now each one of our posts have one
category belongs to one category and
categories has many Popes so each
category can belong to many pots so
let's just add look like the
relationship that we're gonna create is
obviously we're gonna need to create a
private key because we need a property
for this we're gonna call this so we we
are inside the post of PHP so we're
gonna create the category relationship
first category and this is where things
is changing a little bit so we're not
gonna use column like this what we're
gonna do gonna do power M and we're
gonna do the type of relationship one so
we said each each one of our posts has
so many posts I have one category in
category 1 category has many posts so
let's do is can be 1 in 20 to 1 and it
takes two main important things the
first one is the target target entity
the target entity where is the one that
we are trying to make the relationship
with in our case is the category that
the second parameter is gonna be mapped
or inversed by now one thing very simple
too
keep in mind if you like this is
inversed by and Matt why you want to
invert you want to use inverse Y on the
table that is going to be holding the
foreign key okay just remember it this
way if you cannot make sense of n
inverse by is going to be you should use
inverse by on the entity that is going
to be holding the foreign key now in our
case the table that is going to be hard
to be holding the foreign key to the
category is obviously the post so what
we're going to do is we're going to go
in first god I just sped inverse quite
correctly the inverse by we're gonna do
by category now this category that we
have right actually not category post
get that post
so this pole this post that we created
right here is gonna be something that we
would create it's a property like this
are we gonna create in our category of
HP so let's go ahead and do that just
like the other class we need to create
post relationships so we're gonna create
a property which is going to which is
the relationship between which is going
to relate to the post no Chuck Sarah
just to our m and we're gonna do one too
many so one category belongs to can be
on many many just thank you for the
target entity would be the post and is
going to be mapped by because the
foreign key would be on the other term
so we gotta do its category we're gonna
hit enter and as you can see we need so
this this is the basic stuff that you
need to generate a basic basic basic
relationship when we need to do right
now is to generate some post some
getters and setters for outpost
and for our category properties we just
created so you can go ahead and do it by
hand if you want to but I'm not gonna
bother I'm gonna do
ohpa bin slash console I'm gonna use the
make command you can make entity make
entity and I'm gonna regenerate and as
you can
is going to generate some stuff so I'm
gonna put Center doesn't see it updated
welcome eyeglasses brought post and
category and type that just created the
amount of getters and setters that we
just created for category is going to be
much different and a lot as you can see
it's going to be adding posts to an
array and the great collection that we
have right here and it's going to be
removing that as well from that so
that's how you set up a really basic
relationship now let's go ahead and see
what is going to happen if I just try to
create some way to create nothing is
changing but I want to have a field
writing that is going to allow me to
select which category is almost belongs
to what we're going to do is we're gonna
go back to our for post type and we're
gonna add a key like to you so we're
gonna add a field not a key it's going
to be called now I'm gonna put this as
the namespace as I'm gonna use the same
name that I used for in my post of the
HP which is category so let's go ahead
and do that so I'm gonna name this
category now this is the part that is
going to be different we can have been
using an entity type
let's show let's see what that looks
like so we're going to be using integer
please pay attention to the name space
and if we do it for a just like this
it's not going to work obviously is kind
of throw an error it's gonna tell you
that we need a class option which is
missing so we need to pass the array of
options and we need to specify the class
and the class in this case would be I
want you to vote all the categories that
I that you have in my database into this
place so what we're gonna do is we're
gonna go ahead and go category yes and
it's from the entity namespace and we're
going to go to class and we're gonna go
ahead and refresh
as you're gonna see it's it's not going
to work obviously because once again and
once more I forgot to actually migrate
everything to the database so let's go
ahead and do that against HP like a
nutmeg but doctrine schema updates for
us I'm gonna enter as you can see for
created queries were executed this time
so if i refresh this as you can see I
get a list of categories which is empty
right now so what I'm gonna do is I'm
gonna jump to my database I'm gonna just
go ahead and create something so I'm
just gonna go ahead and add like two
useless queries or categories that we
just just for the sake of demonstration
insert something it's called this close
and death so close they're two things
that are related and we have those so
what we're gonna do right now let's go
ahead and see if this is going to be
filled okay so we have an error and
that's because like we actually have
some data now what what I was trying to
do is it was trying to access the list
that it was trying to generate it it was
generated that it was generating this
list right here this drop-down based on
the category the category itself is just
an object and it does not know how to
render an object as text so what we need
to do is we need to go to a category two
PHP and we need to implement a magic
function called two string which is
going to be called whenever the actual
code does not know how to turn your
object into a string and basically what
we want to put in this case Israel we
just want to return the name of the
category so it's what we're gonna do is
this and get me to make like that so
let's go ahead and refresh and that is
going hopefully you come to solve our
problem so as you can see if i refresh
that i'm gonna get two categories right
here now let's go ahead and try to
create something that's cool
you thanks
put some image yeah let's just see what
that doesn't matter just close this and
let's hit say and as you can see
something happened so this is a new
category I'm gonna go out as you can see
I go back to my post you're gonna notice
that I have a categorical one so how do
we display the category again let's go
back to our show function to display
that so I'm gonna go to post show the
HTML and that's so we already have
access to that so what I'm gonna do is
I'm gonna make this p.m. and I'm gonna
do post doc category if I do post doc
category is coming to work that's
because okay this is messed up but this
matter this this is the category that we
just have and it does know how to render
an object into a string because we just
implemented that function but we still
have access to the entire object for
example if I want to get the ID of the
category I can do post doc category
don't IP that is going to give me the ID
of one which which I can use me to
generate some URL if I want to or
something else so that's probably gonna
cover this part of the application which
is relationships now one thing that I
want to do let's say for example that I
want a single query that is going to
generate some mention all right but it's
going to get me everything that I need
for example the title the category on a
single object for example in this case
as you can see I have to go all stock
title I have to go post of category
thoughts I need to get the ID what if I
want to use something that is going to
give me the title in the post ID without
having to go through because this could
get really messy if you have like really
complicated relationships so what we're
gonna do in this case is we now go ahead
and take a look at the repository so the
repository that I was avoiding since the
beginning is just something so each
entity in your your application has a
real poster and within that repository
what you can do is you can create custom
queries and custom functions that you
can use to pair things
for example in our case category
positive positive positive what I want
to do is I want to create a new function
now you have access to defined all and
all that because we are extending some
stuff but you can actually as you can
see right here we have the font file on
blank file I'll find by but we actually
can make our own so let's go ahead and
create something we can do a public
function and then let's do find by
custom just to show you that's fine so
fine by something that's called
customers right now and this is you know
what the skull it's fine but I find most
with category and just and I'm gonna
pass this an end which is going to be
the idea of the post so what I'm gonna
do is I'm gonna actually use the query
builder in this case now what I'm going
to do is I need to create a query bit
this creates query builder we need to
give it an alias and that alias will be
in a string and in my case since I'm
using post I'm gonna use P okay what I'm
gonna do next is that's it for this what
I'm gonna do next is I need to query
builder and add just I'm gonna select so
what do I want to select I wanna select
a couple of stuff first I want to select
the title so how do I select the title
I'm gonna do P dot right which is going
to give me it's like now I'm gonna keep
this pretty simple I'm gonna leave it
like this and one more thing that I have
to do because I have to add a where
clause because I want to search the deep
I what I'm gonna do obviously is I'm
just gonna go ahead and do where like
this and it's going to take P dot V and
I can just use even P if I want to but
I'm gonna see it second and the second
parameter
what we kind of you know what this needs
to match or actually I think we can just
do something like this so I think we can
just go ahead and do the ID like that
and then we can go ahead and set the
parameter so maybe we can go sit down
sir sit around and we can give it the ID
so for example um use an idea right here
I can give it the key is my key and the
value is ID right there just come to be
pass from here now let's return
something we're gonna return the query
builder but we are not gonna return the
creative adorable that's because it's a
query with it's not a results or
something what we're gonna do is we
gonna call it query which is going to
get the query first and then from that
you want to get result and that's how
you get actually results from that and
not just one called each one in the
query window so let's go ahead and see
if this is going to work I'm gonna go
back to my show is that's what I'm gonna
experiment the most so let's go to our
host controller and I will show action
I'll show Dad what I'm gonna do is I'm
gonna get rid of this and I'm gonna put
back my and eat that's because I'm lazy
and in all that so what I'm gonna do it
is post story and I want to add I want
to have access to foster now let's
riposte equal the post repository story
I want to find fine post with category
but so I have access to that function
that I just created
it's going to ask me for some ID which I
have right here I'm just gonna press
that that and I think we are ready to
dump this post and see what we're gonna
get so let's go ahead and refresh this
page all right so we have an array as
you can see right here title as you can
see the data right now is it tightly is
in the rain it's no longer post that's
because I'm returning some cast now
let's go back to our find post and this
month as we said we want a category so
how do we return
the first thing we need to do is we need
to add a select now we need access to
not just do can you don't category like
this I mean it's not going to as you can
see it's gonna get an invalid expression
what we need to do is we need to join
both classes and then you can access
that property in how to do that it's
pretty easy but you got good it was
inner join and from the Peapod category
and this is pretty amazing about
something I like this Peter category we
need to give an alias to the class that
we're gonna use it's gonna be so
category it's going to be C and this is
all we have to do right now so what we
can do is just go ahead and do C
thoughts category although them because
inside the category we have then if I go
ahead and research this but you can see
I'm gonna get an array of two values
first one is going to be new first one
is going to be title of the post and
then we're gonna get the name of the
category right there and we can even get
other stuff so for example I can select
and I can get the seed of a new to the
category deep and I can even get the
post or lightly add select we can add
Peapod ID and that is going to give me
the ID as you see now we have a problem
you're gonna notice that we have the
title yeah he's just one for the X for
both the category I eat in the Box deep
and it's going to only get me one
because it's gonna get confused as you
can see this is the eighth eighth quote
so it's giving me just one just
accountable for the ID now what you want
to do in this case we want to give them
some aliases and add select stuff and as
in add select what I want to do is I'm
gonna give this an alias so this is
going to be pass up title I'd be like
that and the category is going to be as
categoryid so I'm just good cat I think
at some place and as you can see all
right it's not gonna have any problems
the title I this is not because I did it
is basically post ID somebody probably
was screaming at the screen while I was
screaming at something that it's matter
so we have titled post aidid and them
and the category hit me so that's how
you can create a custom query builder
and that's what the repository is for
now obviously I'm not gonna be using
that because it's it's gonna require me
to change my view and I don't want to do
that because I'm place so what I'm gonna
do is I'm just gonna keep everything as
Ross and that's how you can use now I
want to talk about one more thing before
I and this and that is going to be
services services are something that
you're going to be hearing a lot when
you're dealing with center and basically
everything in Symphony is a service for
example this is a service so if you
remember from the password so where's
the registration controller as you can
see this is a service that we just you
to encode the password a service is just
some class that you're gonna create and
you're gonna call somewhere to have to
do something now as I said Symphony is
full of services everything inside
Symphony is a service and all these
services that within saintly lives
inside something called in the container
and the container is just a big massive
object of basket of objects that contain
whatever you're gonna need you can
actually go ahead and take a look of the
all these services that you have inside
Symphony by doing constant and do a
debug chain if I do that in just hit
enter I'm gonna get a very long list of
all the available services inside my
application as you can see this is
extremely extremely long so I'm not even
gonna try to go to today just try and I
fail I succeeded action so what we gonna
do actually is we're just gonna go ahead
and try to create our service but why
would you try to
even create service how how is that even
helpful now as you can see in this case
this is a really simple example that
just creates a post and uploads an image
and as you're gonna see it gets pretty
messy for example we are not chicken if
the chicken but I'm not chicken if the
user already has an image we are not
trying to remove the old image for
example from this to save some space on
the server we are just uploading the the
actual image so what we're gonna do is
we're gonna try to refactor this and
we're gonna try to put everything into a
service as I said don't like this
service the concept confuse you it's
just a class as you're gonna see we're
gonna create a folder I'm gonna call it
service because that's where it's going
to cool it was going to contain and I'm
gonna go ahead and do create a file and
I'm gonna call this file uploader so in
my case I just created a service that is
going to be caused by upload them and
this file uploader is basically it's
just going to install upload some files
for me now I'm gonna give it a name
space it's gotta be app services and the
class is just gonna be five o'clock it's
not going to extend anything as I said
is just a very basic simple class that
you can use what we're gonna do is we
gonna create so another we're gonna make
a function actually creates function
we're gonna call it upload file and this
file and this upload file is going to
get rid of all the junk that we have
right here is just going to give me a
file name that I'm gonna set right here
and I'm gonna be done I'm gonna gain
some you know I'm gonna get in some
lines about three lines or something so
upload file needs to have a file base
with an app code so that first you know
what let's just take these lines that
we're trying to get rid of let's go
ahead and paste them here as you can see
we have some errors everything is is red
the first thing we need to do to pass
through this file upload upload file is
the file that well we are actually
trying to upload that is going to be a
type uploaded file so we're gonna call
this file which is going to get rid of
the two red lines that we have right
here
the second thing is that you're going to
notice is we have this get parameter
which is not defined in this class so
what we're going to do is we need to
inject something in our controller in
this class and the way to do that is by
using a construct controller and to what
we going to need to pass there is
probably the container sorry for the
wheel cut as I said we need the
container right here so what we're gonna
do is this get hunter is getting this
from the container so what we're gonna
do is and this is something that a lot
of people are probably gonna be hating
me for but I'm gonna include the
container interface right here so I'm
gonna do trainer and I'm gonna
initialize this field because I'm using
pitch the storm is coming to initialize
this for me now I can just access the
container while doing this container and
then get actually you know what it's not
the attendant arrows alright it seems
like it's the right one so I'm gonna go
and I'm gonna do container games or
something and I'm not really sure if
this is going to work what I'm gonna see
in a second if this is the correct
interface dear correct container that I
can check right here as I said he is
going to eight that is yeah so we have
that now what I want to return from this
is the file name that I just generates
it right here because I want to I'm
gonna be reusing it to save it to the
database I'm gonna do we're gonna do a
return to file name that now we can go
to our post controller and immediately
find it how do we get access to that
function that we just created we have
two things first you can use dependency
injection or wiring of course now auto
wiring is just something even a notice I
just created this class and Symphony is
gonna is going to know how to
instantiate it I included the container
interface in it and is going to know
that it's going through me that that it
is going to provide that for it let me
show you that in action
it's pretty amazing it's to file folder
like that let's give it a name and let's
use it we're just gonna do five closer
and we're gonna upload the file now
which file be doing an upload is the one
that we have right here let's that's
that and as I said this upload file
function is going to return a file name
so we can just reuse that so what we're
gonna do is I'm gonna save that
somewhere so I'm going to find name like
that and as you can see we have we found
we add less lines now let's go ahead and
see if this is going to actually work or
is it's just mess I'm going to try to
create a new post I'm gonna give it
almost good service and I'm gonna give
it an attachment and this image is
probably too big I'm not sure if it's
going to work and actually it works so
let's go to a post with surface as you
can see I get the same results by using
a surface now as I said this is going
symphony is going to know that my my
service exists and it's going to use
that and it's going to check if this
needs anything it's going to inject
whatever it needs is going to provide
whatever this service needs to that that
is auto wiring of course an auto wiring
could be configured inside surfaces dot
young so this file right here is where
the magic happens I didn't see our
wiring is set to true and as the Commons
is set self-explanatory in says it
automatically injects dependencies in
your services and the auto compare it
automatically restore your services as
commands and subscribers now I'm
probably gonna end the video right here
right after I talk about services but
because I feel like all the event stuff
and subscribers and all that advanced
stuff not for beginners complete
beginners but there's plenty of
resources that you can check if you want
to get more information about that now
one more thing that I want to mention
about this is if you don't have our
wiring it's set to true or false
you're gonna have to explicitly
configure your
now at this point you you are just that
you gotta be good if you just sit all
the way into - I've been using it and
there's no problems with that but
sometimes you're gonna need to pass some
some some custom stuff to your to your
services for example let's say that we
have an e bat let's suppose we have a
service that sends an email and we want
to pass something to that an email that
is going to be in the environment part -
that how we can do that is pretty simple
all you have to do is come right here
now this is in the case if we have
already set to false it's not the case
and one what we're going to do is we're
going to do app services and find
uploader
and we're gonna give it so it can it be
either this this is so in our case in
our case if I go back to the container
and I try to debug so one one thing that
you can do is you can just include some
some some world in our case we have file
uploader so if I do that so if I do
people file up it's going to give me the
service that I have it's kind of tell me
that the service ID is being same as the
class that's because I didn't provide
anything and the class is this one and
it's going to say if it's public it is
shared in our shared and also wired and
all that so is that you yes that's why
Symphony knows how to use it let me go
back to my service and try to explicitly
use my you know my service so I can give
it a name so a service ID I can give it
something custom service ID like this I
can change this one I want for example
to custom now what I need to do I need
to give it a class the class yeah it's
file uploader is working that's fine and
the second thing so this is a class
obviously if I go ahead and try to you
know search for file upload
I'm gonna get
it seems like it's not registering this
stuff
I was actually expecting to get glue
just see if I can search or custom file
and yes indeed I had that so I have the
custom file uploader but I just told
them that I just created that doesn't
matter so I have access to that and I
can even set Ottawa to fault if I want
to I'm never gonna do that I'm just
trying to show something but if I want
to pass some some renters to or
arguments to my function what I had to
do to my service what I have to do is I
have to argument that and I need to pass
whatever functions you know whatever it
whatever I need or example if you want
to pass just a regular string that is
going to be taken in the service
no one let's go ahead and create a new
service I'm gonna straight all this
stuff time it's called sin okay class
let's go let's give it a name space it's
gonna be abscess and the class is going
to be obviously this and let's create a
new public function and I'm gonna call
this patient doesn't matter I'm gonna do
it anyways now we're gonna create our
controller so and then ensure that our
constructor so it's too public
and as I said I want to pass the email
that it's going to be used right here so
I can do that so yeah let's just come to
me so I can do that that and let's
initialize this value right here not
need to do that but what I'm gonna do is
I'm gonna run this email and I'm just
gonna die right away
so how do we pass the email to this as I
said this is how
to do it so what I'm gonna do is I'm
gonna do up services as I said you could
either create a custom name or you can
just pass the class directly onto it's
going to know about it so multiplication
and we gonna pass some arguments so
arguments like that example like this so
let's go email and admin like that and
let's go ahead and see so we need to
call back somewhere so I'm just gonna
call it in by post in trouble I'm just
gonna do occasion yeah let's go ahead
and refresh this page you all get again
we've done
that's create I need to go too late and
as you can see I successfully passed
that that value now a couple of more
things let's say that you want you don't
want to hard-code this each time one
thing you can do is you can create a
parameter called for example email admin
email and you can have if you want to
use this parameter right here by the
value by the key which can do it here's
the percent symbol and you can do email
or whatever so if I do that I'm gonna
get the same thing
okay that gets it all right so I'm
checking the documentation it seems like
I don't even need to
I'm forgetting about everything
something is so big that it not unless
you are working that simple myself so
the story is go into the solving yeah
that's what I need to do I need to fix
that now this is how you can pass like a
string so I can even have like a you
know a regular string show you both ways
now let's say that I want to pass some
arguments on some other service so let's
say that I need the fight uploaders so
let's go ahead and see what we can get
in this we're going to refresh this page
and see it does know my file upload it's
gonna know that because I said otherwise
it's true and all I need to say right
here is in my services Hammond is the
man so that's pretty much it that's how
that's what I believe is the beginner's
guide into symphony for that's what I
think you need to get started now
there's a lot and plenty of other stuff
that you need to be looking at for
example the event and you need to learn
Ambassador you can create services about
that we have listeners we have we have
some doctrine we have some custom types
that you can create we have custom
annotations there's plenty of plenty and
plenty of stuff that you can do but
that's gonna be it for this thank you
guys for watching if you have any
questions please don't hesitate to
contact me or leave them down below and
I will do my best to a needs help so
thank you guys for watching all I'll
leave you two