How to build a router in PHP (like Laravel) 2022 - PHP Project - PHP Tutorial Beginner to Advanced
HTML-код
- Опубликовано: 7 сен 2024
- 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/...
💖 Show Support:
www.buymeacoff...
📧 Join Newsletter:
amirkamizi.com...
👇 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
I like your teaching style, even more I admire your depth of PHP knowledge. This is really helpful.
Thank you very much. I'm glad to hear you liked it
The only php guy i recognise his ability of simplifying php is a top tier. God bless bro🥷 all love brother
oh thank you very much for your kind words. I'm glad you liked it.
Wonderful video! I also have it working with query parameters. Had to modify the regex.
Thank you very much.oh yes changing the regex to be able to take into account the query parameters is very good. thank you
Great Job! Thank you. I always have been interedted in this topic
Thank you! I'm glad it could help you
The goat !
Thank you very much. I'm glad you liked it 🙏🙏
many thanks i rally struggled with the redirecting thing
much love
Thank you. I'm glad you find it helpful
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
}
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.
keep up the good work man !
Thank you very much Mohammad 🙏
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 🐘
Thank you very much. I'm very glad to hear that! :)
why does print_r($SERVER['REQUEST_URI']); is empty
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.
Great Job! Thank you
Thank you Michal! I'm glad you liked it
Where are you from long ago?
My man
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
W video
Thanks a lot, could you please share the code?
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.
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 ?
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
@@amirkamizichannel
Thanks a million, Amir.
So helpful. I deeply appreciate
@@NedumEze It's my pleasure
@@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?
@@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.