PHP Attributes - Simple Router With Attributes - Full PHP 8 Tutorial

Поділитися
Вставка
  • Опубліковано 8 січ 2025

КОМЕНТАРІ • 108

  • @hansschuijff
    @hansschuijff 2 роки тому +12

    A more difficult subject to get into, since the php doc itself that you showed at the start of the video, is not very explanatory or clear about what attributes are and how they work.
    After seeing this lesson through and making the effort to code along with you I am now confident that I understand it enough to be able to use it.
    What made it clear for was that you showed that Attribute is just another class you can use and extend by creating your own Attribute classes.
    In the end it didn't seem difficult anymore and that shows me you're a great teacher.
    Thanks, Gio. Top job.

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому

      I'm really happy to hear that, thank you so much 💙

  • @aeiou...
    @aeiou... Рік тому +8

    I was planning on buying a PHP course on udemy because I want to enhance my php knowledge. I'm a laravel developer and I feel like I already forgot the most part of pure php. I'm glad I found this series, and its FREE!! Thank you!

  • @aymanaoun2136
    @aymanaoun2136 2 роки тому +1

    For being an awesome technical teacher!

  • @Vitalii-m6r
    @Vitalii-m6r Рік тому +3

    This course is extremely useful if someone would like to dive right into PHP. Thanks a million!

  • @gaborjonas2740
    @gaborjonas2740 3 роки тому +17

    Quality, modern PHP stuff, keep it up.

  • @benderbg
    @benderbg 4 місяці тому

    The grind is real.

  • @kinvain
    @kinvain Рік тому +1

    This is the best attributes explanation! Thank you for sharing!

  • @gabrielcarvalho7964
    @gabrielcarvalho7964 2 роки тому

    Thanks!

  • @chrisodillman3355
    @chrisodillman3355 Рік тому +1

    i love you man !!! thank you so much

  • @iambasanta
    @iambasanta 3 роки тому +4

    This whole tutorial playlist is outstanding. Learning a lot of things from you. Thank you !!!
    Would you make a video on when to use a framework , If the problems can be solved with vanilla PHP then is it worth to do it with framework? I know framework increases the development speed. But using it for smaller projects ? What are your opinions I would love to hear it.

    • @ProgramWithGio
      @ProgramWithGio  3 роки тому +5

      Thank you 💙. Yes I'll make a video about that, can't give an exact time but towards the end of the series probably. My opinion is that unless the app is very small, using a framework will only speed up the work. I personally use Laravel for pretty much everything.

    • @iambasanta
      @iambasanta 3 роки тому

      @@ProgramWithGio Laravel

  • @Zubbee
    @Zubbee 2 роки тому

    Wow, this one was pretty cool. I'm like seeing how we are advancing and yet you always seem to say that it can't be used in production... and I'm like, men there must be a ton of things to learn. I followed and have updated my router class. Thanks Gio. Awesome. I'm moving on...

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому +2

      Its not about learning ton of new things, its that this codebase is for education only, it lacks some important features that you would get from a full scale framework like Laravel or Symfony.

    • @Zubbee
      @Zubbee 2 роки тому

      @@ProgramWithGio Ok. I think when I start looking into these frameworks I'll understand more of what you are saying. Notwithstanding, I'm truly learning alot

  • @reza.kargar
    @reza.kargar Рік тому

    You just described the topic perfectly 👌🏻🙏🏻

  • @Markov39
    @Markov39 Рік тому

    Really well made video 👏

  • @drcod3r329
    @drcod3r329 3 роки тому +5

    im really amazed the information you have how did you get all these knowledge please !

    • @ProgramWithGio
      @ProgramWithGio  3 роки тому +8

      Thank you. I don't know everything by heart. A lot of research & preparation goes into each video, for example this video took me over 15 hours to make including editing.

    • @drcod3r329
      @drcod3r329 3 роки тому +1

      @@ProgramWithGio
      i see that im just really amazed your channel deserves alot and also if possible do a laravel short videos and tips.

  • @alextc4199
    @alextc4199 Рік тому

    hmm, you are awesome.
    other speakers tell about his vacation, mood, dogs and at the end about php attributes )))
    thank you

  • @feldinho
    @feldinho Рік тому

    Quality stuff! Thanks!! :)

  • @ЯоКуассиЖан-Клод

    Thanks you very very much! you are the best)

  • @truthteachers
    @truthteachers Рік тому

    Bro, i have one problem. At timestamp 12:23, I set the attribute "#[Route('/examples/generator')]". This works fine when the url has "/examples/generator" but fails when the url has the ending "/" like "/examples/generator/". I tried defining 2 attributes with the second one having the ending "/" and yet it failed stating i cannot have duplicate attributes. How do i address this problem?

    • @ProgramWithGio
      @ProgramWithGio  Рік тому +1

      You could modify the Router class (resolve method) and trim of any trailing slashes

    • @truthteachers
      @truthteachers Рік тому +1

      @@ProgramWithGio Bro, the problem resolved itself when we defined the attribute as repeatable. Then i defined 2 routes. It worked. But the trimming the trailing slashes would be a better option. Tq so much.

  • @hossamragab1428
    @hossamragab1428 8 місяців тому

    Realy how Could this playlist are for free!!!! God save you . And realy we are apperciate your effort thaks alot

  • @holdenjack
    @holdenjack Рік тому

    Amazing video as always!!! Please could you create a version two of this video with parameters. It's something i just can't get my head around. Some store it in a $request->getParams(), others have it public function($param1, $param2) etc. Would be extremely helpful. Thankyou!!!! :)

    • @ProgramWithGio
      @ProgramWithGio  Рік тому +1

      Thank you 🙏. We use SlimPHP later in the series which comes with built in router and param support so you won't have to build it from scratch

    • @holdenjack
      @holdenjack Рік тому

      @@ProgramWithGio Yes i saw that video too. Sadly it didn't help me learn the underlying technology in how dynamic routers with parameters work. Thanks tho :)

  • @MrLion22
    @MrLion22 Рік тому

    Hello, you make really great videos and I look at them with great enthusiasm. But one thing I miss here, namely: independent of a 3rd framework (such as Slim), how could you form a group here with the router class? I lack this here and also the know-how for it. I would be very happy if you could also make a separate video for this. Thank you in advance.

    • @ProgramWithGio
      @ProgramWithGio  Рік тому +1

      Thank you, and thanks for the suggestion, I'll add it in my list of videos to make 🙌

    • @MrLion22
      @MrLion22 Рік тому

      @@ProgramWithGio Thank you, I'm really looking forward to it. Do you know roughly how long it might be according to your calendar? Because then I can explicitly adapt to it.

    • @ProgramWithGio
      @ProgramWithGio  Рік тому +1

      @@MrLion22 no idea honestly, I'm pretty swamped right now with work and videos. Gotta finish PHP series and then Laravel. So can't give you a rough ETA on it unfortunately

    • @MrLion22
      @MrLion22 Рік тому +1

      @@ProgramWithGio OK, I can understand that. Then I'll just let myself be surprised and just wait and see. Hope it comes out soon. Thank you and for the quick reply ;-)

  • @cirhanne
    @cirhanne Рік тому

    RegisterRoutesFromControllerAttributes has a nested loop it can be very slow if you have many routes + many http requests. This method is called in every http request right?

    • @ProgramWithGio
      @ProgramWithGio  Рік тому +2

      Yes, there needs to be a caching layer for a more optimal solution. This is just an example demonstrating how attributes can be used for routing.

  • @enderozata9438
    @enderozata9438 3 роки тому

    gI have made a conditional listing in this coding, but what I want to do is to find the selected data from the database and have it listed, for example, when the pediatric service is selected, the patients hospitalized in the pediatric service will be listed.

    • @ProgramWithGio
      @ProgramWithGio  3 роки тому

      I can't really help you without knowing what the problem is or having access to the code.

    • @enderozata9438
      @enderozata9438 3 роки тому

      @@ProgramWithGio let me assign the code

    • @enderozata9438
      @enderozata9438 3 роки тому

      What I want to do is to list the data in the selectbox, whichever is selected, from the database.
      for example child service is selected in selectbox
      I want to list the patients treated in the pediatric service to the screen.

  • @lahoucineoldakdim7778
    @lahoucineoldakdim7778 2 роки тому

    For simplesity and perfermance, In this case of routing I prefer to include a config file return array of all routes and merge it with array variable in the Route::class

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому

      For sure, its fine if you have a few routes but as you add more routes then extracting it to a config routes file is the better way. Great tip 👍

    • @lahoucineoldakdim7778
      @lahoucineoldakdim7778 2 роки тому

      @@ProgramWithGio
      Yes, suppose we have a folder named routes contains: web.php , api.php and admin.php
      We can load it easy using this loop:
      foreach (glob(__DIR__ .'/routes/*.php') as $route) {
      require_once $route;
      }

  • @dhirendrasinghnegi7948
    @dhirendrasinghnegi7948 Рік тому

    What if controller class have more than one method , how $method will get the right method of controller class , video reference 10:44

    • @ProgramWithGio
      @ProgramWithGio  Рік тому

      Because route is defined in attribute & the method name is there on the controller method definition, keep watching & at around 12:00 you will see multiple methods within controller

    • @dhirendrasinghnegi7948
      @dhirendrasinghnegi7948 Рік тому +1

      @@ProgramWithGio Got it , Thanks Sir

  • @bakosyy
    @bakosyy Рік тому

    Hey Gio. I see that you declare strict types by doing something on "

    • @ProgramWithGio
      @ProgramWithGio  Рік тому

      What do you mean? If you mean the autocomplete part thats just the IDE. Also I have it set up so that it adds strict types to all new PHP classes created within the IDE

    • @bakosyy
      @bakosyy Рік тому

      @@ProgramWithGio yup, I mean IDE set up that adds strict types to all new PHP classes. What do you use for that?

    • @ProgramWithGio
      @ProgramWithGio  Рік тому +1

      ​@@bakosyyit's just a setting on PHPStorm. I believe it's a PHP stub template file. You can Google it and find how to edit it on PHPStorm

  • @_nirajghimire
    @_nirajghimire 3 роки тому +2

    Can we expect "Laravel the right way" with some awesome project ?

    • @ProgramWithGio
      @ProgramWithGio  3 роки тому +1

      🙂. I don't know yet, after this my plan is Laravel & Shopify. We'll see

  • @codewithsheikh2805
    @codewithsheikh2805 Рік тому

    Do i need to understand reflection Api before I can use Attributes

    • @ProgramWithGio
      @ProgramWithGio  Рік тому +1

      If you want to make custom attributes & functionality then yes. If you want to use built in attributes or attributes that come with frameworks/package then not really

    • @codewithsheikh2805
      @codewithsheikh2805 Рік тому

      @@ProgramWithGio ok so I'm beginner in php do i need to know about this before i can start learning some framework?

    • @ProgramWithGio
      @ProgramWithGio  Рік тому +1

      @@codewithsheikh2805 there are other topics you should be familiar with before moving into frameworks. Attributes isn't really necessary for that. Best way to know is to start the framework and if you get stuck or don't understand something, then learn about that specific topic and do it in parallel.

    • @codewithsheikh2805
      @codewithsheikh2805 Рік тому

      @@ProgramWithGio thanks bro.

  • @ntdash2153
    @ntdash2153 2 роки тому

    Sooooo, #Attributes are for PHP what @Decorators are for Typescript ?🤔🤔🤔🤔

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому +1

      I don't know Typescript but from quick Google it seems yes

    • @ntdash2153
      @ntdash2153 2 роки тому

      ​@@ProgramWithGio You seem like the type to like type hinting so I suggest that you give it a try 👍

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому +1

      @@ntdash2153 Thanks. I will when I have the need for it, I mainly work on back-end currently.

  • @alisson8320
    @alisson8320 2 роки тому

    do you think about making a laravel course too? also thank you for the videos ur a god

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому

      Thank you. After PHP series is over I'll be doing more Laravel content, not a full course like PHP but more project oriented

  • @KIKOmanasijev
    @KIKOmanasijev 2 роки тому

    Can we generate getters & setters functions for properties using Attributes?
    Ex:
    #[Getter]
    #[Setter]
    private $somePropertyName;
    This should generate the following functionality:
    getSomePropertyName(){...}
    setSomePropertyName(){...}

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому

      Not sure to be honest. You can use IDEs for that to generate getter & setters. If you mean dynamically then you can use magic __get & __set methods. Not sure I understand the use case.

    • @codewithsheikh2805
      @codewithsheikh2805 Рік тому

      @@ProgramWithGio Isn't using __get and __set method bad practice?

    • @ProgramWithGio
      @ProgramWithGio  Рік тому

      @@codewithsheikh2805 depends on the use, there are pretty good usecases for it

  • @tobiomotosho6849
    @tobiomotosho6849 2 роки тому

    Will you cover AJAX?

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому

      Not directly since it's not a PHP thing. Might use it in a project though

  • @khanbadshah7987
    @khanbadshah7987 Рік тому

    your job is very great. appreciated you. but a lot of things we not understand. if I compare with other programmers, you are tackle a problem with complex method. I don't know if I have the basic skills of php or your method is complex? please explain. but don't mind bro

    • @ProgramWithGio
      @ProgramWithGio  Рік тому

      I'm not sure what you mean. What problem did I tackle with complex method? Attributes is not complex, it's a feature that I'm explaining and providing a usecase. If it seems complex then you can start from first section maybe, are you following the series from the beginning?
      Note that this is third section of the series which is advanced PHP, so if it seems hard I would advise to watch the series from the beginning. There are a lot of videos in first & second sections

  • @fafaratze
    @fafaratze 2 роки тому

    its like python decorator.. also like flask

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому +1

      Maybe 🤔. I'm not familiar with Python decorators or flask so not 100% sure.

  • @donnyturizo111
    @donnyturizo111 9 місяців тому

    Porque no ponen así pero en español

  • @sergeisurin2963
    @sergeisurin2963 Рік тому

    👍

  • @enderozata9438
    @enderozata9438 3 роки тому

    pleplease can you help me

  • @davidmutua6971
    @davidmutua6971 8 місяців тому

    I wish you could have done a separate video without all the Route stuff. This is for people whom find this and just want to use Attributes. Found one ua-cam.com/video/oSo4xbP6ZYo/v-deo.html&ab_channel=GaryClarke

    • @ProgramWithGio
      @ProgramWithGio  7 місяців тому

      Well, in this playlist the Route part fits in nicely. You can use Attributes for many different scenarios, Routing is one of them & a good example as well

  • @seoonlyRU
    @seoonlyRU 2 роки тому

    like

  • @bernhardd626
    @bernhardd626 Рік тому

    This is a anti-pattern way of programming. Use interfaces for routable controllers instead and register it by calling the interface method. Much clearer. Using the reflection class is never a good way of programming.

    • @ProgramWithGio
      @ProgramWithGio  Рік тому +1

      I respectfully disagree. Don't see this as antipattern, most popular frameworks use both attributes/annotations & reflection API so not sure what you mean?

    • @bernhardd626
      @bernhardd626 Рік тому

      @@ProgramWithGio My main point is that there are other and clearer options.
      I observe that in practice the Reflection API is used too often and incorrectly, resulting in cluttered and poorly maintainable code.
      Please always try to find another solution first, typically with interfaces.

    • @ProgramWithGio
      @ProgramWithGio  Рік тому +1

      @@bernhardd626 we didn't use it wrongly or poorly in this video. Reflection API exists for a reason and Attributes is a great feature which you can't really use without Reflection API. Doing routing via attributes/annotations is a very common practice & there is absolutely nothing wrong with it.
      As I said before most popular frameworks utilize Reflection API the same way and use it pretty often in their source.

  • @MelonPython
    @MelonPython 3 роки тому +2

    Hello Gio! Do you have Discord / Are you going to start one? I'd love to join it and learn from a very experienced programmer like yourself.

    • @ProgramWithGio
      @ProgramWithGio  3 роки тому

      Hello. Yes I have a discord, though I am not very active on it. You can find the link in channel about page.

    • @hopeofglory8108
      @hopeofglory8108 3 роки тому

      Was about to ask the exact same Q! Been looking for a good PHP community. Have had a great experience in Kevin Powell's for the front end stuff.

  • @enderozata9438
    @enderozata9438 3 роки тому

    Do you have instagram