WEBVTT

00:00.140 --> 00:00.650
Okay guys.

00:00.650 --> 00:03.830
So in this quick video we are going to fix the router.

00:03.860 --> 00:05.690
Let me remind you what's the problem.

00:05.690 --> 00:08.600
You are going to the main page.

00:08.630 --> 00:11.720
It should accept the query parameters.

00:11.750 --> 00:13.940
After you add a question mark.

00:13.970 --> 00:17.000
Yet we have a not found page.

00:17.030 --> 00:24.890
So I would say that this is actually a problem because this way with the current router, there is no

00:24.890 --> 00:29.180
way we can pass some additional parameters to our pages.

00:29.210 --> 00:34.790
If we would like to create something like before, we've made an example.

00:34.790 --> 00:38.510
When we filtered the products, this wouldn't be possible.

00:38.900 --> 00:47.750
That's why we just need to jump to the router and focus on that part on the normalize URI.

00:49.100 --> 00:50.510
So let's see the problem.

00:50.510 --> 00:57.110
Let me add any query parameters to a page and you can see it's instantly broken.

00:57.140 --> 01:04.700
Though this is a perfectly fine method not only in PHP but generally in websites to pass some additional

01:04.700 --> 01:06.650
parameters to a page.

01:06.650 --> 01:13.550
This should be working and it should be displaying the main page same as slash contact with those query

01:13.550 --> 01:14.510
parameters.

01:14.690 --> 01:17.900
This should also be working and it's not.

01:18.260 --> 01:23.810
And we're going to be using a Strtok function to fix this.

01:25.130 --> 01:28.280
So first I'm going to call Strtok.

01:28.280 --> 01:30.530
And then I'm going to explain that.

01:31.490 --> 01:34.880
So we need the string and a token.

01:34.880 --> 01:39.440
So we are passing the URI and the token is the question mark.

01:39.470 --> 01:45.020
Now let me explain how this function works and why this is the best choice.

01:45.530 --> 01:55.670
So this function will split this string into smaller chunks delimited by this delimiter, which in our

01:55.670 --> 02:03.350
case we want it to be a question mark and it returns the string before the delimiter.

02:03.350 --> 02:05.180
This is exactly what we want.

02:05.210 --> 02:12.860
We want everything before the question mark and the reason why we use it is it is easier to use and

02:12.860 --> 02:16.220
more efficient than other alternatives.

02:16.550 --> 02:23.690
You probably also have seen me using a function called explode, which might seem similar.

02:23.690 --> 02:31.310
We can also add a separator and convert a string into an array, but then we end up with an array,

02:31.310 --> 02:35.240
so we need some additional handling in that case.

02:35.270 --> 02:39.410
Also, if we are missing this question mark.

02:39.620 --> 02:47.300
So if there are no parameters passed then this edge case is also handled fine.

02:47.930 --> 02:52.160
Now if I would go to where are we on the contact page.

02:52.190 --> 03:02.270
Let me jump to contact get route and if I would now like to var dump the get super global which should

03:02.270 --> 03:04.730
contain all the query parameters.

03:07.160 --> 03:17.600
I can see it is empty, but as soon as I come up with any query parameters like color equals red, I

03:17.600 --> 03:19.160
have them available.

03:19.160 --> 03:24.920
So that's everything we had to do to deal with this router limitation.

03:24.920 --> 03:29.480
And by the way, we've learned a useful function.
