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/ - วิทยาศาสตร์และเทคโนโลยี
I am not gonna use any framework for my freelance projects, ever again. Thanks to you! ❤
The most useful video demonstrating the MVC pattert in php that i watched so far.
Thanks
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
Thanks a lot for your feedback
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
Thanks for the feedback.
Thanks a lot, Max, quite a helpful video.
Hey this help me so much thanks
I am confused. How does the passing an array named params to a callback function associate the variable to the incoming request query params?
It is useful. Thank you for sharing
Thanks for watching!)
Awesome information Thank you so much
Thank you
Thanks alot mate it actually works
Happy it works!!!
great guide!
can you do a guide about adding middlewares? particularly for validate requests values
Can you add dynamic routing along with pattern match ??
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?
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!
awesome i would interested to see a whole MVC framework😍
Great idea
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?
It is possible
dude how can you handle scenario of items/{item-id} in this aproach ? thanx
Are you looking to add a parameter for a GET request?
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?
What do you mean when asking your question?
@@MaxPronko :-) I dont understand why we should use http_foundation?
Can you share the source code used here
Hello can you use php built in webserver and connect to database?
Yes, why not?
Hey after implementing the router i am getting a database erro saying: "Database Error: could not find driver", please help me
Have you sorted the issue?
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.
The index.php is located in the public folder, that is a document root
@@MaxPronko thanks, cd public
Hi how to include css file to phtml please I cant find
www.w3schools.com/Tags/tag_link.asp
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
You should enable mod_rewrite module if you use Apache
PHP' = Her personal productive! American Tribes
Hi Max,
Can you provide the link to the code in the video?
Thanks much.
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
Let me record a video and explain
@@MaxPronko ok Sir thanks we are waiting Sir
First :D
This is brilliant and very useful. Thanks again for all your hard work Max :)
Thanks Ash for the feedback. It means a lot to me.
so cool dude!
Thanks
Where is source code
It should be on my github mcspronko
Акцент шик))))
Дякую👍
Єврейський трохи роутер. Але більш-менш.
Над вимовою попрацюй. Або веди канал на рідній мові.
Дивись канали на рідній мові, бо може щось не зрозуміло буде.
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
What use case do you want to achieve with name/surname?
@@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}
@@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("/(?
like this one : $router->get('/contact/{$id}', function($param){
echo $param;
});
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
It looks like your callback wasn’t setup properly, please check the code before this call.