How to build a router in PHP (like Laravel) 2022 - PHP Project - PHP Tutorial Beginner to Advanced

Поделиться
HTML-код
  • Опубликовано: 10 окт 2022
  • In this PHP tutorial I'll talk about building a router in PHP. this might look simple but it's very powerful.
    🎓 PHP Course Beginner to Advanced:
    www.udemy.com/course/php-begi...
    💖 Show Support:
    www.buymeacoffee.com/amirkamizi
    📧 Join Newsletter:
    amirkamizi.com/#newsletter
    👇 Follow Me On Social Media:
    Twitter: / amir_kamizi
    LinkedIn: / amir-kamizi
    👇 Checkout My website
    amirkamizi.com
    Thank you for watching.
    If you found it useful:
    ✔️ Like & Subscribe
    ✔️ Share
    If you have any suggestions, questions, or opinion, please leave a comment below. I’m looking forward to hearing from you!
    ⭐️ Contents ⭐️
    0:00 - Intro
  • НаукаНаука

Комментарии • 37

  • @BruceElgort
    @BruceElgort Месяц назад +1

    Wonderful video! I also have it working with query parameters. Had to modify the regex.

    • @amirkamizichannel
      @amirkamizichannel  Месяц назад

      Thank you very much.oh yes changing the regex to be able to take into account the query parameters is very good. thank you

  • @Asp.net_Developer
    @Asp.net_Developer 11 месяцев назад +1

    The only php guy i recognise his ability of simplifying php is a top tier. God bless bro🥷 all love brother

    • @amirkamizichannel
      @amirkamizichannel  11 месяцев назад

      oh thank you very much for your kind words. I'm glad you liked it.

  • @AndrewKwabula
    @AndrewKwabula 11 месяцев назад +1

    I like your teaching style, even more I admire your depth of PHP knowledge. This is really helpful.

    • @amirkamizichannel
      @amirkamizichannel  11 месяцев назад

      Thank you very much. I'm glad to hear you liked it

  • @jadidlar4765
    @jadidlar4765 Год назад +1

    Great Job! Thank you. I always have been interedted in this topic

  • @ftmullah
    @ftmullah 3 месяца назад +2

    W video

  • @MohammadDLitoo
    @MohammadDLitoo Год назад +1

    keep up the good work man !

  • @mastro870able
    @mastro870able Год назад

    Great Job! Thank you

  • @cristhianjhlcom
    @cristhianjhlcom Год назад

    Hello, I just found your channel and I think it's awesome, I'll check out all your videos. :D keep up the great work 🐘

  • @rerain8193
    @rerain8193 9 месяцев назад

    many thanks i rally struggled with the redirecting thing
    much love

  • @monzur
    @monzur 8 месяцев назад +2

    That's an awesome project.
    Thanks. I think here we, need to handle the 404 error page.
    Otherwise, a user can't determine that's the right path.
    here I share my little code to handle 404.
    if (preg_match($pattern, $currentUri)) {
    // do something
    }else{
    //Here we can load 404 controllers or just print the message
    }

    • @amirkamizichannel
      @amirkamizichannel  8 месяцев назад +1

      Thank you for sharing that. exactly we can create a fallback route so in case it didn't match anything we would show a 404 page.

  • @user-fl8zu1rt2r
    @user-fl8zu1rt2r 4 месяца назад +1

    why does print_r($SERVER['REQUEST_URI']); is empty

    • @amirkamizichannel
      @amirkamizichannel  4 месяца назад

      sorry for late response. I hope you've figured it out till now. if it's giving you empty result check your .htaccess file and your directory and make sure it's pointing to the right place.

  • @NedumEze
    @NedumEze Год назад

    Thanks Amir for this.
    Please, may I ask?
    If your index.php were in a "public" folder, how will the RewriteBase rule be then?
    Will this be correct: /php_course/public ?

    • @amirkamizichannel
      @amirkamizichannel  Год назад +2

      I'm glad you liked it. yes exactly. if it was in localhost/php_course/public then you would write /php_course/public. but note that the base path for the project and the location of index.php file are 2 different things.
      for example in this video the project was in php_course so in the browser I would go to localhost/php_course
      so if for you it's in php_course/example you would need to go to php_course/example. this would be base path of the project. it would be good if the index file is in the base path. it can be in another folder but it might create some unexpected behaviours. for exmaple your base path might be example and your index.php file might be in example/foo/index.php. you can make it work but it would behave a bit "strange" :)
      take a look at apache documentations
      httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
      and
      httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
      I hope I could help you with you question

    • @NedumEze
      @NedumEze Год назад +1

      @@amirkamizichannel
      Thanks a million, Amir.
      So helpful. I deeply appreciate

    • @amirkamizichannel
      @amirkamizichannel  Год назад

      @@NedumEze It's my pleasure

    • @NedumEze
      @NedumEze Год назад +1

      @@amirkamizichannel
      I took up your challenge Sir.
      Implemented Composer Autoloader and populating the remaining Methods in the Models Folder.
      Truth? It's hard! And I am struggling.
      Question: The files in the Views Folder should be mainly HTML pages AND NOT CLASSES?

    • @amirkamizichannel
      @amirkamizichannel  Год назад +1

      @@NedumEze I'm glad to hear that you took the challange. I'm sure you're going to do it. yes the views can be .php files and inside them the format is like a normal html file. there is no need to use classes. later you can use a templating language like blade that laravel uses.

  • @nagdali9209
    @nagdali9209 11 месяцев назад +1

    Where are you from long ago?
    My man

    • @amirkamizichannel
      @amirkamizichannel  11 месяцев назад

      oh thanks man for asking. I've had some issues that I was trying to deal with but now everything is much better and this week I will upload new content again. I hope everything is going well with you

  • @machinelearning2578
    @machinelearning2578 Год назад +1

    Thanks a lot, could you please share the code?

    • @amirkamizichannel
      @amirkamizichannel  Год назад +1

      offf I've just seen your comment. sorry for such late response :)
      I'm glad you liked the video. my main goal for these videos is that I go step by step so the learner could go on and actually code the project themselves. that's why I haven't shared the source codes.