From 36139b2f8878f9c9dadccca231a37b184e98cc85 Mon Sep 17 00:00:00 2001 From: Amigo <49749100+aamigo@users.noreply.github.com> Date: Thu, 25 Jul 2019 16:03:15 +0200 Subject: [PATCH] Updated 051 Dynamic Router Implementation Explained (markdown) --- ...Dynamic-Router-Implementation-Explained.md | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/051-Dynamic-Router-Implementation-Explained.md b/051-Dynamic-Router-Implementation-Explained.md index 63ab0f4..6ddb288 100644 --- a/051-Dynamic-Router-Implementation-Explained.md +++ b/051-Dynamic-Router-Implementation-Explained.md @@ -46,6 +46,32 @@ Now the other place also need to change is 'series'. 'sermon' should also be 'se 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. -### The Interface -???? -Let's go back to the interface and let me show you [00:08:22](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m22s) 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 now I'm gonna show this to you 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 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 say get list query Ok so This is the one We want to change [00:09:35](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m35s) The get the dynamic get As well as speaking about serieses The same is true of that We have this List query get series ID Sermons that we also want to change And so we not changing 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) Right to correct code to whatever view you add it because we've added some custom Scripting Sorry placeholders within the script So let's take the first one is this sermon Where is it Sermon series So in custom script we scroll down to the bottom there is now a new Tab here option here Add PHP Parse method in router little bit of explanation there [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 So you see it looks very familiar it's got his place holders And it has a specific It has a specific S View 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 gonna be used this this Dynamic get This Would be replaced with that specific site view's value Ok that's just to give you a heads up About the place holder and that's what makes it dynamic So that you can use it in any site view and it will automatically write this Because really the the display of the page is actually 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 And 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 obviously update that and Replace multiple values So Here we want to within this one Did the default option here will actually resolve our issue because Remember these two values were not the same JCB's Dynamic build actually changed this value to Sermon instead of [00:11:57](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m57s) Leaving it The same And there is a very good reason For that Usually this would be the correct response but in this case because of complexity I'm not gonna explain It isn't the correct response and so you want these two values to be the same And it is basically the site view's name So we could just save it close this The next one we wanna do is this sermon preacher And it was also [00:12:25](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m25s) Having the same issue basically So we We gonna do the the same kind of Just add the the custom Option To ensure that these two values remain the same And then the last but not least was this category It is also behaving Incorrectly And really 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 actually category And that is primarily because it is using the Sermon table To to start instead In the Sermon table We have a joint here too category If you can see there And so it does load the category and [00:13:12](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m12s) the tweak You see that we are actually using This ID And this is a category ID So it should actually go look for the category And build the parse method based on the category And so here We also gonna Just 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 actually a category This this name In effect is actually gonna be ignored Because it's gonna not be looking for this tables value is gonna go to the category table And look for the value there Ok so this will resolve this this issue We can save and close this one [00:13:59](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m59s) So now we have Done some customisation to our router Just by adding those Values to the dynamic get If we compile our components now It will automatically fall back Unto those Values Just install again [00:14:21](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m21s) And now let's go look at the code So we see here That it did exactly what he wanted it added preacher preacher there And this is now Categories is true And We see the series is series And so now at least we know that this actual 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 really gonna make it too much better There was also the idea of adding some custom scripting into the built Method And we will look at that And I invite You and anyone else too To get involved On this on GitHub just 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) I get in contact with me and let's let's work together This is so what we've done so far But like an all iterative developing concepts Will continue improving this To the point where it really serves as well And holds up with changes also happening in Joomla itself Ok well thanks for watching +### 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) + +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 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 serieses, 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 + +[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 this 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. + +### JCB Change sview to sermon + +[00:11:56](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m56s) + +JCB's dynamic build changed sview value to sermon instead of leaving it the same. There is a very good reason for that. Usually this would be the correct response but in this case because of complexity, I'm not going to explain it, isn't the correct response and so you want these two values to be the same and it is the site view's name. We could just save it close. + +### 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 the same kind of just add the the custom option to ensure that these two values remain the same. + +### Resolving Category + +[00:10:39](https://www.youtube.com/watch?v=hYycPLbaMos&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m39s) + +Then the 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 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 this tables value, 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 unto those values. Just install 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 all iterative 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. \ No newline at end of file