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

แชร์
ฝัง
  • เผยแพร่เมื่อ 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
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 39

  • @thehunter11
    @thehunter11 หลายเดือนก่อน +1

    The goat !

    • @amirkamizichannel
      @amirkamizichannel  29 วันที่ผ่านมา

      Thank you very much. I'm glad you liked it 🙏🙏

  • @jadidlar4765
    @jadidlar4765 ปีที่แล้ว +1

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

  • @AndrewKwabula
    @AndrewKwabula ปีที่แล้ว +1

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

    • @amirkamizichannel
      @amirkamizichannel  ปีที่แล้ว

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

  • @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 🐘

    • @amirkamizichannel
      @amirkamizichannel  ปีที่แล้ว

      Thank you very much. I'm very glad to hear that! :)

  • @rerain8193
    @rerain8193 10 หลายเดือนก่อน

    many thanks i rally struggled with the redirecting thing
    much love

    • @amirkamizichannel
      @amirkamizichannel  10 หลายเดือนก่อน +1

      Thank you. I'm glad you find it helpful

  • @BruceElgort
    @BruceElgort 3 หลายเดือนก่อน +1

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

    • @amirkamizichannel
      @amirkamizichannel  3 หลายเดือนก่อน

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

  • @ftmullah
    @ftmullah 5 หลายเดือนก่อน +2

    W video

  • @Asp.net_Developer
    @Asp.net_Developer ปีที่แล้ว +1

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

    • @amirkamizichannel
      @amirkamizichannel  ปีที่แล้ว

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

  • @monzur
    @monzur 9 หลายเดือนก่อน +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  9 หลายเดือนก่อน +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 6 หลายเดือนก่อน +1

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

    • @amirkamizichannel
      @amirkamizichannel  6 หลายเดือนก่อน

      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 ปีที่แล้ว +1

    Where are you from long ago?
    My man

    • @amirkamizichannel
      @amirkamizichannel  ปีที่แล้ว

      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.