Updated 034 How to add Custom Buttons in JCB to your component Admin Area (markdown)

Amigo 2019-07-20 11:10:01 +02:00
parent 48ceceb3fa
commit 714bd0de18
1 changed files with 5 additions and 5 deletions

@ -33,19 +33,19 @@ To demonstrate where the code ends up. Save this as a selection in a List view a
[00:07:05](https://www.youtube.com/watch?v=VyBxWpJWb40&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m05s)
Now let us go back to editing that functionality there, and show some more options('Look'). Go to Custom Buttons. Add another button.(See video) Target - call it 'single'. Name - call it 'Work'. The Controller method - 'getDone', and leave Type to 'Default' and then save. [00:07:50](https://www.youtube.com/watch?v=VyBxWpJWb40&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m50s) In the Controller method there is a function called 'getDone'. In the(PHP controller method) a public function is placed. This time we will get the model and do something in the model. You can also get the item values. When this button is clicked, the item opens and it automatically submit the form. It is possible to grab the item's values. The values may differ from those in the database. [00:08:36](https://www.youtube.com/watch?v=VyBxWpJWb40&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m36s) The values could be changed, by clicking that button, and it will submit these changed values. Yet those values has not been saved to the database. If those values need to be in the database, you have to put it there. The model has a save method, and you should do the necessary sanitation, and trigger the save method, and it should store the data. For this purpose the data need to be grabbed, a verification done, and then return either an 'error' or a 'success'. <<<<<<<<<<<<<<<<<<<<<
Now let us go back to editing that functionality there, and show some more options('Look'). Go to Custom Buttons. Add another button.(See video) Target - call it 'single'. Name - call it 'Work'. The Controller method - 'getDone', and leave Type to 'Default' and then save. [00:07:50](https://www.youtube.com/watch?v=VyBxWpJWb40&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m50s) In the Controller method there is a function called 'getDone'. In the(PHP controller method) a public function is placed. This time we will get the model and do something in the model. You can also get the item values. When this button is clicked, the item opens and it automatically submit the form. It is possible to grab the item's values. The values may differ from those in the database. [00:08:36](https://www.youtube.com/watch?v=VyBxWpJWb40&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m36s) The values could be changed, by clicking that button, and it will submit these changed values. Yet those values has not been saved to the database. If those values need to be in the database, you have to put it there. The model has a save method, and you should do the necessary sanitation, and trigger the save method, and it should store the data. For this purpose the data need to be grabbed, a verification done, and then return either an 'error' or a 'success'.
### Checking Within Controller Before Trigger The Model
[00:09:33](https://www.youtube.com/watch?v=VyBxWpJWb40&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m33s)
First we going get the values. We have the data, we can check whether the values that we want to use is there and available. We want to make sure that this is already a saved item. [00:09:51](https://www.youtube.com/watch?v=VyBxWpJWb40&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m51s) Then we at least check whether the id is more than 0. We need to have a name, and then we can check for that. We can do some checking within the controller before we trigger the model, and run the function we intend. Then we triggered the model, we decide what we want to call a method in the model. I chose something random and then we can create that method in the model area. And then do whatever we want to do.
First thing is to get the values. Having the data, check whether the values that is needed is there and available to be used. It is necessary to make sure that this is already a saved item. [00:09:51](https://www.youtube.com/watch?v=VyBxWpJWb40&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m51s) Then check whether the ID is more than 0. It is necessary to have a name, and then check for that. Some checking should be done within the controller before the model gets triggered , and run the intended function. Then the model needs to be triggered , then it should be decided what to call the method in the model. Something random is chosen and then a method can be created in the model area, then do whatever you prefer.
### Logic In The Model Methods
So we [00:10:32](https://www.youtube.com/watch?v=VyBxWpJWb40&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m32s) start doing some logic in the model. We have set up of above controller method. Now we are busy within the model area. Do keep in mind that if the model is unsuccessful, you want to do something, if the data is set, but the model is not being successful, you want to do something, [00:10:55](https://www.youtube.com/watch?v=VyBxWpJWb40&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m55s) and if your data isn't set, we also want to do something. Those are the areas in which we can add some messages that we want to give back to the user, to tell them what's happening. In the model, we are going to perform our task, and when we have achieved our goal, we give back true, whether we have failed, we give back false, and then that would trigger our messages in the controller. This is just giving a basic overview of setting up some model controller connected with a button.
[00:10:39](https://www.youtube.com/watch?v=VyBxWpJWb40&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m39s)
What is being done the model area? Do keep in mind that if the model is unsuccessful, something needs to be done, if the data is set, but the model is not being successful, something needs to be done, and if the data is not set, something needs to be done.[00:10:55](https://www.youtube.com/watch?v=VyBxWpJWb40&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m55s) Those are the areas in which some messages can be added that needs to be returned to the user, to inform them what is happening. In the model, the task gets performed, and when the goal is achieved, return 'true', if it failed, return 'false', and then that would trigger the messages in the controller. This is just giving a basic overview of setting up some Model Controller connected with a button. <<<<<
### Adding Code