From 020a1c4d27ef46c5f42cfa8035465c3c4e5be317 Mon Sep 17 00:00:00 2001 From: Amigo <49749100+aamigo@users.noreply.github.com> Date: Tue, 4 Jun 2019 15:21:06 +0200 Subject: [PATCH] Updated 014 Adding dynamicGet to a Site View (markdown) --- 014-Adding-dynamicGet-to-a-Site-View.md | 37 +++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/014-Adding-dynamicGet-to-a-Site-View.md b/014-Adding-dynamicGet-to-a-Site-View.md index bb0bcb9..f27d6af 100644 --- a/014-Adding-dynamicGet-to-a-Site-View.md +++ b/014-Adding-dynamicGet-to-a-Site-View.md @@ -6,7 +6,38 @@ Hi now that we have the dynamicGet in place, let's add that to a site view and l **Populate Fields From Get's** -You would see there on the right-hand there are 3 fields that you can populate with your dynamicget methods. The first one is where you would add all the custom dynamicgets. There you can add multiple custom dynamicgets. The second one is where you add your main dynamicget as we explained in the dynamicget tutorial. you can add 1 main get method per [00:00:57](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m57s) view or site view. Since it's going to be build in the model, either as a getitem or a getitems. +You would see there on the right-hand there are 3 fields that you can populate with your dynamicget methods. The first one is where you would add all the custom dynamicgets. There you can add multiple custom dynamicgets. The second one is where you add your main dynamicget as we explained in the dynamicget tutorial. you can add 1 main get method per [00:00:57](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m57s) view or site view. Since it's going to be build in the model, either as a getitem or a getitems. It is all depending on the main get whether it's going to be a list or an individual item. Yet you can include custom dynamicgets as many as you like. You also have this data available in your view. These two first fields are used to load the dynamicget to the view. -??? -It is all depending on the main get whether it's going to be a list or an individual item. Yet you can include dynamicgets Custom Dynamic gets as many as you like You also have this data available in your view So these two first fields are used to load The Dynamic get to the view The third one [00:01:37](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m37s) Is used to display the possible way that you might want to implement The code of a specific Dynamic get option You'll see that This one only displays Possible main Gets this one only this place customer gets Where is this displays both The custom and the main kind of Gets Now If you select a [00:02:04](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m04s) let's go to One of these Main Gets Sermon This one here You see that it shows us A list Print out of the possible ways that you might Use the result set [00:02:32](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m32s) Obviously each of these you can copy by clicking in it and then clicking on either right click And Copy or you could click on ctrl V ctrl C and command C to copy respectively the content Sometimes you might only want to use part of it and not the echo statement included Then you can pick from the area where you want to copy and then before letting go [00:03:05](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m05s) Click on control C or command C in a Mac to insure you only grab that section of the text Once you let it go it will select the whole block and then Obviously if you copy it you will copy everything As you can see We then use This code in our default View To display the data In a PHP [00:03:36](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m36s) Fashion You can also get the the customer get here let me show you that one preacher Like you see it says that that Value is gonna be in this preacher And if we look here at the top that is what we are checking for here Make sure that you have a Preacher And then this block Basically deals with displaying the data related to that Information This one here [00:04:08](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m08s) Checks whether the main items are on the on the page and now the main items as you can see Is sermons preacher ID get list So if I go down to that sermon preacher I get List You see that again it shows me that the values are in items And it's in array So I can loop through it and target the the object values And that's what's being done here We first checking whether it's [00:04:38](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m38s) On the page the values Then If we see that it is here We use make use of templates to to display the various Layouts And I will explain in a next tutorial how to use templates in layouts inside Of your site View [00:05:01](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m01s) But this is just quickly showing you how to connect A dynamic get Structure or Methods to your view And then how to make use of the data that are being passed through to the view So this data structures here on the right in red Is basically the the data structure that you can expect From each one of these so if I was to take number sermons As the Method that I want to see [00:05:36](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m36s) Then it shows me that That's possibly the way that it will be packed into the data set So it'll be found in this number sermons is how Now that could change Depending on your custome implementation In your components custom coding areas you might move this data from that Position to something else But the reality is this at least gives you how it would have looked without you You know I'm leaving the [00:06:10](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m10s) The normal Path So this is just Proposing the dataset structure Which ideally would be that you would take this value here And Maybe do this in the code Do a var_dump And then exit And then Basically do a build and go look at this view to see exactly the structure [00:06:45](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m45s) If you are finding that this structure that we've shown isn't working exactly as we expected Often this helps us To sort a map the array and see where What value is found same goes with any of the others You can just grab that area That you want to peek into Put it in var_dump Do a build go look at this page In the in the front of your site And you can see exactly the structure of this This object here [00:07:20](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m20s) Whether it is an array with objects or whatever Is placed inside of this value set through the dynamic get method Now I just want to quickly Peek at the Way that these methods are actually becoming available in your view by going to the code And just looking at Some of the implementations that we've done Ok As you can see we've gone to the front of the site [00:07:55](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m55s) sermon distributor Models And we've opened The preacher model Use the preacher model And As you scroll down you see that there's a get list query This get list query gets sermon as the a Table And then [00:08:18](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m18s) Series as the C table preacher is the D and Categories is the Sorry C D B Is the B table And then it looks for a value in ID And then Sets it equal to preacher And in sure that it [00:08:41](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m41s) The person has access level to the item That's published And then returns it So that is the Get List query in the model Have you go back to our interface you see that we have sermon preacher ID get list as the main [00:09:06](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m06s) And I've opened that Dynamic get here let me just see where is it And you can see that Sermon is set as A the main table And if you open here you see that series is set as C the only looking for those values Preacher said is d only those values Statistics E But it's a list [00:09:36](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m36s) it is Multiple These that are single are part of the list query where is the multiple of it will have its own object sorry it's Method we will Look at that quickly And then We see in the DB table That we have category a single as B Only those values So going back to the code [00:10:01](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m01s) This is the get list query in the get item After we have received the items We look through them And then in this function here get Sermon statistics and then a A generated string Randomly generated string to ensure No conflicting with other methods on the page Puts the values in ID sermons statistics e [00:10:30](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m30s) So that's where the values of place And then basically we have a custom Method here like be shown in the dynamic get you can add custom methods And then returns the items to the page And in the page You have a A file That is called View [00:10:55](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m55s) Sorry view HTML dot. PHP If you open this File you see that there is a get items Method being used to place the items in items And so At the moment we are actually in the view at this stage And that means you can access This set of values Inside of that Class field [00:11:26](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m26s) And so if we go back to our Component Builder You would see if we were to select That method There is the items Corresponding to our code And so we know that the ID in the asset ID in all these are in there if you scroll down You see that there is it sermons is too sticky see it there So that means In the array there is a [00:12:03](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m03s) key value Which has another set of array values in it So you can target these data sets By corresponding pointing Values So that is just looking at the main get Now if we were to look at The other custom get [00:12:28](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m28s) That is been added We'll see that here's preacher Which is a custom get or custom method That is been added And It also has its set of Values and it's database structure and remember we said that we want it to be Link to the preachers ID So can I check for the ID [00:12:53](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m53s) And then Set it to ID And returns the result Same goes with the number of downloads It's also custom method That said To this view because of the custom get that was added And here is the number sermons And we go back to our view dot HTML dot php file We see that those values are respectively being added [00:13:21](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m21s) To preacher Number downloads and number sermons And you can actually use these values in the view by targeting with this number Sermons Now the view itself is As you should know inside of the template folder Under the views preacher And this Main View as we call it all the default view is where that code that we on the page that we looking at right now [00:13:50](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m50s) Being placed All these others are the templates that are extending the site View And they possibly are extended through layouts that are available in the layouts folder So We are we are now just looking at adding The custom get methods to the page in our next to tutorial we are going in depth about adding templates to your Custom Site View And making use of these data sets [00:14:24](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m24s) So That is how you link them your first create the custom get then you come here you link these So these are the linking Fields and these are just so that you can see the code snippets are making use of these fields Respectively And That is custom Gets added to site view Thank you for watching +**Dynamic Values** + +The third one [00:01:37](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m37s) is used to display. The possible way that you might want to implement the code of a specific dynamicget option. You'll see that this one displays main gets. This one displays customer gets. This(Dynamic Get) displays both the custom and the main kind of gets. If you select a [00:02:04](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m04s) one of these main gets, sermon(series.id)(getlistquery). You will see that it shows a list printout of the possible ways that you might use the result set. [00:02:32](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m32s) Each of these you can copy by clicking on it. Clicking either right click and copy or you could click on ctrl C and command C to copy respectively the content. Sometimes you might only want to use part of it and not the echo statement included. Then you can click from the area where you want to copy and then before letting go [00:03:05](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m05s) click on control C or command C in a mac to insure you only grab that section of the text. Once you let it go it will select the whole block and then if you copy it, you will copy everything. + +**Inserting Values Into View** + +As you can see we then use this(Dynamic Values) code in the default view to display the data in a PHP [00:03:36](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m36s) fashion. You can also get the customerget here. That one preacher. That value is going to be in this preacher. And if we look here(default view) at the top, that is what we are checking for. Make sure that you have a preacher, and then this block deals with displaying the data related to that information. This one here(see video) [00:04:08](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m08s) checks whether the main items are on the page. Now the main items as you can see is sermons, preacher.id, getlist. If I go down to that sermon preacher, I get list. It shows me that the values are in items. It's an array. I can loop through it and target the the object values. That's what's being done here(default view). We first checking whether it's [00:04:38](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m38s) on the page the values. Then if we see that it is here, we make use of templates to display the various layouts. I will explain in a next tutorial how to use templates in layouts inside of your site view. [00:05:01](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m01s) This is just quickly showing you how to connect a dynamic get structure or methods to your view. + +Then how to make use of the data that are being passed through to the view. This data structures here on the right in red, is the data structure that you can expect from each one of these(Custom Gets). If I was to take number sermons as the method that I want to see, [00:05:36](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m36s) then it shows me that's possibly the way that it will be packed into the data set. It'll be found in this 'numbersermons'. That could change depending on your custom implementation in your components custom coding areas. You might move this data from that position to something else. But the reality is this(Dynamic Values) at least gives you how it would have looked without leaving the [00:06:10](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m10s) normal path. + +**Var Dump** + +This is just proposing the dataset structure which ideally would be that you would take this(numbersermon) value here, and do this(see video) in the code. Do a var_dump, and then exit, and then do a build and go look at this view to see exactly the structure. [00:06:45](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m45s) If you are finding that this structure that we've shown isn't working exactly as we expected. Often this helps us to map the array and see where what value is found. Same goes with any of the others. You can just grab that area, that you want to peek into. Put it in var_dump. Do a build, go look at this page in the front of your site. You can see exactly the structure of this object here. [00:07:20](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m20s) Whether it is an array or array with objects or whatever is placed inside of this value set through the dynamic get method. + +**Gets In The Code eg: Preacher.php** + +Now I just want to quickly peek at the way that these(Custom Gets) methods are actually becoming available in your view by going to the code by looking at some of the implementations that we've done. As you can see we've gone to the front of the site [00:07:55](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m55s) sermon distributor, models. We've open preacher model, use the preacher model. As you scroll down you see that there's a getListquery. This getlistquery gets sermon as the 'a' table, and then [00:08:18](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m18s) series as the 'c' table, preacher is the 'd' and categories as the 'b' table. Then it looks for value in id. Then sets it equal(=) to preacher. Then ensures that [00:08:41](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m41s) the person has access level to the item that's published, and then returns it. That is the getListquery in the model. If we go back to our interface, you will see that we have sermon (preacher.id)(getlist) as the main. [00:09:06](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m06s) + +**Looking At The Dynamic Get** + +I've opened that dynamic get here. And you can see that sermon is set as 'a' the main table. If you open here(Join View Table - Add) you see that series is set as 'c' the only looking for those(selection) values. Preacher is set as 'd', only those(selection) values. Statistics 'e', it's a list. [00:09:36](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m36s) It is multiple. These(preacher, series) that are single are part of the listquery. Where as the multiple of it will have its own method. We will look at that quickly, and then we see in the Join DB table - add that we have category as single, as 'b' those values. Going back to the code. [00:10:01](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m01s) This is the getListquery, in the getitem after we have received the items, we look through them and then in this function here getSermonstatistics and then a generated string(Fcff_E) to ensure no conflicting with other methods on the page. Puts the values in 'id sermonsstatisticsE'. [00:10:30](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m30s) That's where the values are placed. We have a custom method here. Like we shown in the dynamic get you can add custom methods, and returns the items to the page. + +**Preacher view.html.php Generated Code** + +In the page you have a file that is called: [00:10:55](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m55s) view.html.php. If you open the file you see that there is a get items method being used to place the items in items. At the moment we are actually in the view at this stage. That means you can access this set of values inside of that class field. [00:11:26](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m26s) If we go back to our Component Builder, you would see if we were to select that(sermon (preacher.id)(getlist)) method, there is the items corresponding to our code. We know that the id. and the asset_id, in all these are in there. + +**Checking The Target Datasets** + +If you scroll down, you will see that there is a 'idsermonstatisticsE'. So that means in the array there is a [00:12:03](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m03s) key value which has another set of array values in it. You can target these data sets by corresponding pointing values. That is just looking at the main get. If we were to look at the other custom get [00:12:28](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m28s) that is been added. We'll see that here's preacher, which is a custom method that is been added. It also has its set of values and it's database structure and remember we set that we want it to be link to the preachers id. So can I check for the id, [00:12:53](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m53s) and then set it to id, returns to result. Same goes with the number of downloads. It's also custom method that set to this view because of the custom get that was added. Here is the numbersermons. As we go back to our view.html.php file, we see that those values are respectively being added [00:13:21](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m21s) to preacher. number downloads, and number sermons. You can use these values in the view by targeting with this number sermons. + +**Site Preacher Tmpl Folder** + +Now the view itself is, as you should know inside of the template folder, under the views preacher. This main view as we call it or the default view, is where that code that we on the page that we looking at [00:13:50](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m50s) being placed. All these others are the templates that are extending the site view. They possibly are extended through layouts that are available in the layouts folder. We are just looking at adding the custom get methods to the page in our next to tutorial. We are going in depth about adding templates to your custom site view, and making use of these data sets. [00:14:24](https://www.youtube.com/watch?v=vEJZe6XqHJE&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m24s) That is how you link them, your first create the custom get, then you come here, you link these. So these are the linking fields and these are just so that you can see the code snippets are making use of these fields respectively. That is custom gets added to site view.