Updated 051 Dynamic Router Implementation Explained (markdown)
parent
19cc29a106
commit
1c9d7c1853
@ -17,7 +17,7 @@ Your search engine friendly URL is done with the router. JCB also builds the rou
|
|||||||
|
|
||||||
[00:01:26](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m26s)
|
[00:01:26](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m26s)
|
||||||
|
|
||||||
This is explained in the code. In the website there is a root directory 'Joomla mount', 'admin' and then 'components'. In there is Sermon Distributor and there is a file called '`router.php`'.
|
This is explained in the code. In the website, there is a root directory 'Joomla mount', 'admin' and then 'components'. In there is Sermon Distributor and there is a file called '`router.php`'.
|
||||||
|
|
||||||
### parse - switch(segments[ ]) - First Value
|
### parse - switch(segments[ ]) - First Value
|
||||||
|
|
||||||
@ -43,21 +43,21 @@ I know that this is an error because we want to get the value, the id of the pre
|
|||||||
|
|
||||||
[00:06:38](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m38s)
|
[00:06:38](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m38s)
|
||||||
|
|
||||||
Now the other place also needs to change is 'series'. 'sermon' should also be 'series' [00:06:43](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m43s) So this is where the guessing which JCB does dynamically did not match the complexity of our Dynamic Gets. I'm sure that as time goes on we might improve it's guessing. We might get better ways of guessing correctly and within the dynamics of the Dynamic Gets, be able to build this case more effectively. Since we have not done that yet, [00:07:17](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m17s) the quickest way for us to resolve this and which most probably be the most dynamic option, is adding a way that you can replace the snippet of code, targeting the specific view. You will never need to really know what is the view when you do this because they are placeholders. You need only to remember where you add your Dynamic Get.
|
Now the other place also needs to change is 'series'. 'sermon' should also be 'series' [00:06:43](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m43s) So this is where the guessing which JCB does dynamically did not match the complexity of our Dynamic Gets. I'm sure that as time goes on we might improve it's guessing. We might get better ways of guessing correctly and within the dynamics of the Dynamic Gets, be able to build this case more effectively. Since we have not done that yet, [00:07:17](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m17s) the quickest way for us to resolve this and which most probably be the most dynamic option, is adding a way that you can replace the snippet of code, targeting the specific view. You will never need to know what is the view when you do this because they are placeholders. You need only to remember where you add your Dynamic Get.
|
||||||
|
|
||||||
Let me go and illustrate this within the JCB interface. All I wanted to show you here is that we are targeting with this new dynamic implementation, [00:07:53](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m53s) this little snippet, this little area(see video). We are not replacing the whole method, because it is standard, there's not much to do in improving that, and if we do, it will be improving it for everyone. The build function is really working well. I haven't seen any issues with that. At the end of the day, it seems like only the parse method needed a bit of an improvement.
|
Let me go and illustrate this within the JCB interface. All I wanted to show you here is that we are targeting with this new dynamic implementation, [00:07:53](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m53s) this little snippet, this little area(see video). We are not replacing the whole method, because it is standard, there's not much to do in improving that, and if we do, it will be improving it for everyone. The build function is working well. I haven't seen any issues with that. At the end of the day, it seems like only the parse method needed a bit of an improvement.
|
||||||
|
|
||||||
### The Interface Where You Can Make Changes In Dynamic Gets
|
### The Interface Where You Can Make Changes In Dynamic Gets
|
||||||
|
|
||||||
[00:08:19](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m19s)
|
[00:08:19](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m19s)
|
||||||
|
|
||||||
Let's go back to the interface and let me show you where we can make the changes to have the category render correctly. As well as the preacher and the series. Basically, make the changes so that sermon will say series, and this one will say true, [00:08:48](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m48s) and this one preacher would also say preacher. That's basically all we need to do and then this router will work without any errors. Here in the interface, you have Site Views. The Site Views, the ones we want to make changes to his this preacher, the series and the category. I'm going to show this to you a little bit [00:09:15](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m15s) long-winded but bear with me. It's just to make sure everybody is on the same page. If you open preacher, you would see that it has a Dynamic Get called Sermons (preacher id) and it is a (getListQuery). This is the one we want to change. [00:09:35](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m35s) The Dynamic Get, as well as speaking about series', the same is true of that. We have this Sermons (series id) (getListQuery) that we also want to change. We do not change it in the view. The idea was that if we change it in the Dynamic Get it automatically [00:09:57](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m57s) write the correct code to whatever view you add it because we've added some Custom Placeholders within the script.
|
Let's go back to the interface and let me show you where we can make the changes to have the category render correctly. As well as the preacher and the series. Basically, make the changes so that sermon will say series, and this one will say true, [00:08:48](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m48s) and this one preacher would also say, preacher. That's all we need to do and then this router will work without any errors. Here in the interface, you have Site Views. The Site Views, the ones we want to make changes to his this preacher, the series and the category. I'm going to show this to you a little bit [00:09:15](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m15s) long-winded but bear with me. It's just to make sure everybody is on the same page. If you open preacher, you would see that it has a Dynamic Get called Sermons (preacher id) and it is a (getListQuery). This is the one we want to change. [00:09:35](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m35s) The Dynamic Get, as well as speaking about series', the same is true of that. We have this Sermons (series id) (getListQuery) that we also want to change. We do not change it in the view. The idea was that if we change it in the Dynamic Get it automatically [00:09:57](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m57s) write the correct code to whatever view you add it because we've added some Custom Placeholders within the script.
|
||||||
|
|
||||||
### Sermon (series id) - Heads Up For Placeholders
|
### Sermon (series id) - Heads Up For Placeholders
|
||||||
|
|
||||||
[00:10:06](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m06s)
|
[00:10:06](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m06s)
|
||||||
|
|
||||||
Let's take the first one is Sermon (series id). In Custom Script we scroll down to the bottom, there is a new tab option here, Add PHP (parse Method)-in Router'. [00:10:29](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m29s) Click yes, and it will dynamically load what is, what I can consider the most basic implementation of that little snippet. You will see it looks very familiar it's got these placeholders. It has a specific sview placeholder. That's because we're dealing with the site view and it has to have this s in it to replace it with the site view name. [00:10:55](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m55s) So wherever this is going to be used, this Dynamic Get would be replaced with that specific site view's value. That's just to give you a heads up about the placeholder and that's what makes it dynamic, that you can use it in any site view and it will automatically write this. Because the display of the page is based on the database request. Which is built in the URL by the name of the view. As well as the ID of the element. If there are multiple variables being passed [00:11:32](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m32s) to the URL, you can update that and replace multiple values. Here we want to within this one, the default option here will resolve our issue because remember these two values were not the same.
|
Let's take the first one is Sermon (series id). In Custom Script we scroll down to the bottom, there is a new tab option here, Add PHP (parse Method)-in Router'. [00:10:29](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m29s) Click yes, and it will dynamically load what is, what I can consider the most basic implementation of that little snippet. You will see it looks very familiar it's got these placeholders. It has a specific sview placeholder. That's because we're dealing with the site view and it has to have this s in it to replace it with the site view name. [00:10:55](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m55s) So wherever this is going to be used, this Dynamic Get would be replaced with that specific site view's value. That's just to give you a heads up about the placeholder and that's what makes it dynamic, that you can use it in any site view and it will automatically write this. Because the display of the page is based on the database request. Which is built in the URL by the name of the view. As well as the ID of the element. If multiple variables are being passed [00:11:32](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m32s) to the URL, you can update that and replace multiple values. Here we want to within this one, the default option here will resolve our issue because remember these two values were not the same.
|
||||||
|
|
||||||
### JCB Change sview to sermon
|
### JCB Change sview to sermon
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ JCB's dynamic build changed sview value to sermon instead of leaving it the same
|
|||||||
|
|
||||||
### Sermon (Preacher id)
|
### Sermon (Preacher id)
|
||||||
|
|
||||||
The next one we want to do is Sermon (Preacher id). It was also [00:12:25](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m25s) having the same issue. We are going to do the same kind of just add the the custom option to ensure that these two values remain the same.
|
The next one we want to do is Sermon (Preacher id). It was also [00:12:25](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m25s) having the same issue. We are going to do the same kind of just add the custom option to ensure that these two values remain the same.
|
||||||
|
|
||||||
### Resolving Category
|
### Resolving Category
|
||||||
|
|
||||||
@ -75,4 +75,4 @@ The next one we want to do is Sermon (Preacher id). It was also [00:12:25](https
|
|||||||
|
|
||||||
Then last but not least was this category. It is also behaving incorrectly and it's only because it [00:12:47](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m47s) didn't detect that this is a category. That is primarily because it is using the Sermon table to start instead in the Sermon table we have a Joint here to category it does load the category. [00:13:12](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m12s) In the Tweak you will see that we are using JRequest ID, and this is a category ID. It should go look for the category and build the parse method based on the category. In Custom Script we are also going to add [00:13:33](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m33s) a true to this getVar, which tells the getVar method that this is a category. This name in effect is going to be ignored. Because it's not going to look for the value of this table, it is going to the category table and look for the value there. This will resolve this issue. We can save and close. [00:13:59](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m59s)
|
Then last but not least was this category. It is also behaving incorrectly and it's only because it [00:12:47](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m47s) didn't detect that this is a category. That is primarily because it is using the Sermon table to start instead in the Sermon table we have a Joint here to category it does load the category. [00:13:12](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m12s) In the Tweak you will see that we are using JRequest ID, and this is a category ID. It should go look for the category and build the parse method based on the category. In Custom Script we are also going to add [00:13:33](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m33s) a true to this getVar, which tells the getVar method that this is a category. This name in effect is going to be ignored. Because it's not going to look for the value of this table, it is going to the category table and look for the value there. This will resolve this issue. We can save and close. [00:13:59](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m59s)
|
||||||
|
|
||||||
Now we have done some customization to our Router just by adding those values to the Dynamic Get. If we compile our component now, it will automatically fall back to those values. Just install it again. [00:14:21](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m21s) Let's go look at the code. We see here that it did exactly what we wanted, it added preacher, preacher there. This categories is true, and we see the series is series. At least we know that the router will behave correctly. This is the first step of our improvement to the router. [00:14:49](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m49s) It seems to me that we already have a very workable situation and this is going to make it so much better. There was also the idea of adding some custom scripting into the built method. We will look at that and I invite you and anyone else to get involved on this on GitHub. If you know how to improve his even more then please [00:15:16](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h15m16s) get in contact with me and let's work together. This is what we've done so far. But like an alliterative developing concepts we will continue improving this to the point where it really serves as well and holds up with changes also happening in Joomla itself.
|
Now we have done some customization to our Router just by adding those values to the Dynamic Get. If we compile our component now, it will automatically fall back to those values. Just install it again. [00:14:21](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m21s) Let's go look at the code. We see here that it did exactly what we wanted, it added preacher there. This category is true, and we see the series is series. At least we know that the router will behave correctly. This is the first step of our improvement to the router. [00:14:49](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m49s) It seems to me that we already have a very workable situation and this is going to make it so much better. There was also the idea of adding some custom scripting into the built method. We will look at that and I invite you and anyone else to get involved in this on GitHub. If you know how to improve his even more then please [00:15:16](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h15m16s) get in contact with me and let's work together. This is what we've done so far. But like alliterative developing concepts we will continue improving this to the point where it serves as well and holds up with changes also happening in Joomla itself.
|
Loading…
Reference in New Issue
Block a user