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

Amigo 2019-07-19 14:54:28 +02:00
parent d9df40e2da
commit abe98a247f

@ -33,9 +33,12 @@ 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, by showing you some more options('Look'). Go to custom buttons. Add another button. 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.<<<<<<<<<<<<
Now let us go back to editing that functionality there, by showing you some more options('Look'). Go to custom buttons. Add another button. 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. Since the moment this button is clicked, you are inside of the item and it automatically submit the form. The values of those items can be grabbed but it may be different values than that which are 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 have not been saved to the database.<<<<<<
We can also get the item values. Since the moment you click this button you're inside of the item and it automatically submit the form. We can grab those items values, it could be different values [00:08:36](https://www.youtube.com/watch?v=VyBxWpJWb40&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m36s) from what's in the database. Just keep that in mind, because you could change the values, then click that button and it will actually submit these new changed values. And yet those values have not been saved to the database. If you want those values to be in the database, you'll need to put it there. I'm not going to demonstrate how to do that, but the model has a save method, and you should do the necessary sanitation, and [00:09:12](https://www.youtube.com/watch?v=VyBxWpJWb40&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m12s) trigger the save method, and it should store the data. I'm just going to grab the data. I'm just going to do a little verification maybe, and then return back either an error or a success.
If you want those values to be in the database, you'll need to put it there. I'm not going to demonstrate how to do that, but the model has a save method, and you should do the necessary sanitation, and [00:09:12](https://www.youtube.com/watch?v=VyBxWpJWb40&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m12s) trigger the save method, and it should store the data. I'm just going to grab the data. I'm just going to do a little verification maybe, and then return back either an error or a success.
### Checking Within Controller Before Trigger The Model