This is a usefull button in AJAX applications.
Open de installer. Create a new action: /tests/examples/apibtn In the view you just created put this code:
echo new TAPIButton('Click me!', '#result-click', '/test/example/apibutton_call/');
Create another action, this time of the type (JQUERY): /test/examples/apibutton_call
This time in your controller put this code:
<?php
function apibutton_callJQUERY(array $args = []){
// this is the target you set on the button
$target = $_POST['target'];
// this renders the content of the view in the target
Barebone\jQuery($target)->html($this->view->get_html());
}
<?php
use Barebone\HTML\TAPIButton;
// some div in your view <div id="result-click"></div>
// as soon as you click the button a ajax call is made to the controller /showcase/barebone/apibutton_call/
$btn = new TAPIButton('Click me!', '#result-click', '/showcase/barebone/apibutton_call/');
echo $btn;
// the result is rendered in the div in the view
// long way around better understandable
$btn2 = new TAPIButton('Click me!');
$btn2->setTarget('#result-click');
$btn2->setRoute('/showcase/barebone/apibutton_call/');
$btn2->data('Ithink', 'therefore i am');
$btn2->data('Action', 'do.this.now');
echo $btn2;
<button role="api-button" data-target="#result-click" data-route="/showcase/barebone/apibutton_call/">Click me!</button> <button role="api-button" data-target="#result-click" data-route="/showcase/barebone/apibutton_call/" data-Ithink="therefore i am" data-Action="do.this.now">Click me!</button>