Custom PHP OOP Router without PHP libraries

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 เม.ย. 2021
  • This PHP routing is the simplest and easy-to-implement routing system in PHP. The routing is based on the Apache .htaccess file and uses an Apache Rewrite module.
    Learn PHP and Magento 2 at the magemastery.net
    Build User Login with PHP and MySQL playlist
    • Build User Login with ...
    Build User Registration with PHP & MySQL playlist
    • Build User Registratio...
    Support me on Patreon
    / maxpronko
    Learn Magento 2 on Mage Mastery
    magemastery.net
    Promotion on this channel: max@pronkoconsulting.com
    Subscribe for more videos!
    --
    Twitter: / max_pronko
    Website: www.maxpronko.com
    Business Enquiries: www.pronkoconsulting.com/
  • วิทยาศาสตร์และเทคโนโลยี

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

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

    I am not gonna use any framework for my freelance projects, ever again. Thanks to you! ❤

  • @4rmboy666
    @4rmboy666 6 หลายเดือนก่อน +1

    The most useful video demonstrating the MVC pattert in php that i watched so far.

    • @MaxPronko
      @MaxPronko  2 หลายเดือนก่อน

      Thanks

  • @firstignitor
    @firstignitor 2 ปีที่แล้ว +2

    From now on I can't forget the name Max. Max the PHP routing master.. thank you
    ..en like the voice - audible enough to make me understand.. thanks once more again

    • @MaxPronko
      @MaxPronko  2 ปีที่แล้ว

      Thanks a lot for your feedback

  • @marshalldteach1109
    @marshalldteach1109 ปีที่แล้ว +7

    I always use a framework because of routing but for my small projects, it's kind a overkill. So this is perfect for my next project. Thanks Max

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

      Thanks for the feedback.

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

    Thanks a lot, Max, quite a helpful video.

  • @lucassouzasilva6842
    @lucassouzasilva6842 2 ปีที่แล้ว +2

    Hey this help me so much thanks

  • @catch_me_outside_how_bout_dat
    @catch_me_outside_how_bout_dat 2 ปีที่แล้ว +3

    I am confused. How does the passing an array named params to a callback function associate the variable to the incoming request query params?

  • @NhatNguyen-xo9gs
    @NhatNguyen-xo9gs 3 ปีที่แล้ว +3

    It is useful. Thank you for sharing

    • @MaxPronko
      @MaxPronko  3 ปีที่แล้ว

      Thanks for watching!)

  • @PrakashPrakash-sn3do
    @PrakashPrakash-sn3do 3 ปีที่แล้ว +1

    Awesome information Thank you so much

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

    Thanks alot mate it actually works

    • @MaxPronko
      @MaxPronko  2 ปีที่แล้ว

      Happy it works!!!

  • @MrLinuxFreak
    @MrLinuxFreak 2 ปีที่แล้ว +2

    great guide!
    can you do a guide about adding middlewares? particularly for validate requests values

  • @MrJBisoy
    @MrJBisoy 2 ปีที่แล้ว +2

    Can you add dynamic routing along with pattern match ??

  • @lorenzochukwuebukaobi8898
    @lorenzochukwuebukaobi8898 2 ปีที่แล้ว +2

    Thank you so much for this video it was helpful. How do you add http headers using this routing system to prevent cors errors when building an API?

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

    Hi Max
    Thank you very much for your tutorial. It has been really helpful for me.
    Instead of using Laravel which is a huge framework for just creating a simple website, your tutorial is indeed great.
    My question here is about twig, I would like to add twig in your tutorial but I kind of a bit lost. I would appreciate if you can give me some guidelines.
    Thanks!

  • @outerstring8747
    @outerstring8747 3 ปีที่แล้ว +2

    awesome i would interested to see a whole MVC framework😍

  • @saifulbayan9597
    @saifulbayan9597 3 ปีที่แล้ว

    Hi Max, Thanks for Great Video.
    I have some question about this router in php w/o libraries:
    1. how to implement other http verb like PUT, PAtCH or DELETE to make the router restfull?
    2. if i have some placeholder in Request URI param, how to replace it with some string i wanted. For example when i want make custom slug:
    $router->get('/post/{slug}, Post::class, postDetail($param)),
    and goal URI i wanted just like this /post/awesome-post.
    is possible to achieve that with that approach?

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

      It is possible

  • @grumpyjarl7336
    @grumpyjarl7336 2 ปีที่แล้ว

    dude how can you handle scenario of items/{item-id} in this aproach ? thanx

    • @MaxPronko
      @MaxPronko  2 ปีที่แล้ว

      Are you looking to add a parameter for a GET request?

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

    Thanks, I´m currently learning the http_foundation and your lesson helped alot understanding how it works! thanks!
    BUT why? why do it like this? It gives us an object orientatet way of doing things, but it seems like a lot of hassle for doing it like this.......
    so why do it like this? is it more secure or?

    • @MaxPronko
      @MaxPronko  2 ปีที่แล้ว

      What do you mean when asking your question?

    • @basisit3511
      @basisit3511 2 ปีที่แล้ว

      @@MaxPronko :-) I dont understand why we should use http_foundation?

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

    Can you share the source code used here

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

    Hello can you use php built in webserver and connect to database?

  • @asifurrahman5436
    @asifurrahman5436 2 ปีที่แล้ว

    Hey after implementing the router i am getting a database erro saying: "Database Error: could not find driver", please help me

    • @MaxPronko
      @MaxPronko  2 ปีที่แล้ว

      Have you sorted the issue?

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

    There is no index.php in the home directory, how does it work? I got stuck at 1:45. The requested resource / was not found on this server.

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

      The index.php is located in the public folder, that is a document root

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

      @@MaxPronko thanks, cd public

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

    Hi how to include css file to phtml please I cant find

    • @luckydev3911
      @luckydev3911 2 ปีที่แล้ว

      www.w3schools.com/Tags/tag_link.asp

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

    hello, I created a custom router like this, it works on php local server, but the problem is that it don't work on XAMPP and 000webhost, only the home page works

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

      You should enable mod_rewrite module if you use Apache

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

    PHP' = Her personal productive! American Tribes

  • @manishdeshpande
    @manishdeshpande 2 ปีที่แล้ว +2

    Hi Max,
    Can you provide the link to the code in the video?
    Thanks much.

  • @faratanzaki
    @faratanzaki 7 หลายเดือนก่อน

    Hi sir it's helpful for me because i even build a complete script with it, but i came to blog post part in which i was stuck on how to make it pass variable to the routher like that get(/post/{$id}, Post::class.'::index') but it is not working pls how would i implement it like that

    • @MaxPronko
      @MaxPronko  7 หลายเดือนก่อน

      Let me record a video and explain

    • @faratanzaki
      @faratanzaki 7 หลายเดือนก่อน

      @@MaxPronko ok Sir thanks we are waiting Sir

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

    First :D

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

      This is brilliant and very useful. Thanks again for all your hard work Max :)

    • @MaxPronko
      @MaxPronko  3 ปีที่แล้ว +2

      Thanks Ash for the feedback. It means a lot to me.

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

    so cool dude!

  • @rssimran4800
    @rssimran4800 2 ปีที่แล้ว

    Where is source code

    • @MaxPronko
      @MaxPronko  2 ปีที่แล้ว

      It should be on my github mcspronko

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

    Акцент шик))))

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

      Дякую👍

  • @olezhonnv3215
    @olezhonnv3215 2 ปีที่แล้ว

    Єврейський трохи роутер. Але більш-менш.
    Над вимовою попрацюй. Або веди канал на рідній мові.

    • @MaxPronko
      @MaxPronko  2 ปีที่แล้ว

      Дивись канали на рідній мові, бо може щось не зрозуміло буде.

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

    Hi nice work! I've followed all the video and I created a system as you taught. Some advice about passing parameters like users/$name/$surname ? Thanks

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

      What use case do you want to achieve with name/surname?

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

      @@MaxPronko hi, that is just an example. I said $name and $surname just as an example but I would have said $slug, $id...
      The use would be the same as codeigniter routing or laravel routing.
      I'm looking for more examples and I'm seeing it needs to use regex to interpreting signs like {$id}

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

      @@MaxPronko Searching here and there, I tried to modify the code in this way, I paste here just the foreach inside the route method.
      There is always something wrong, can you give me some tips? Thank you!
      foreach($handlers as $handler):
      $params_values = [];
      $params_keys = [];
      preg_match_all("/(?

  • @faratanzaki
    @faratanzaki 7 หลายเดือนก่อน

    like this one : $router->get('/contact/{$id}', function($param){
    echo $param;
    });

  • @khaledeladawe7769
    @khaledeladawe7769 2 ปีที่แล้ว

    call_user_func_array($callback, [
    array_merge($_GET, $_POST)
    ]);
    it's not working I have this error: GET /about - Uncaught TypeError: call_user_func(): Argument #1 ($callback) must be a valid callback, no array or stri
    ng given

    • @MaxPronko
      @MaxPronko  2 ปีที่แล้ว

      It looks like your callback wasn’t setup properly, please check the code before this call.