References Getting Started Getting Started Architecture Architecture Application Application Window Window WebView WebView Deployment Deployment Components Components Framework Integrations Framework Integrations Examples Examples Community Community github GitHub github Get Started arrow_up_right
Getting Started Getting Started Architecture Architecture Application Application Window Window WebView WebView Deployment Deployment Components Components Framework Integrations Framework Integrations Examples Examples Community Community

WebView

WebView Configuration Events Schemes API Bindings API Data API Scripts API Web Components API Battery API Network API Security API Getting Started Architecture Application Window WebView Deployment Components Framework Integrations Examples Community

Bindings API

You can register custom PHP functions to call them from the client.

The API is available in the WebView::$bindings property.

$app = new Boson\Application();

$app->webview->bindings; // Access to Bindings API

Binding

You can create a function that can be called directly from WebView.

$app = new Boson\Application();

$app->webview->bindings->bind('foo', function () { 
    var_dump('Executed!');
});

WebView also provides a more convenient way (facade method bind()) to bind arbitrary PHP function.

Just use WebView::bind() instead of bind method from WebView::$bindings.

$api = $webview->bindings;

$api->bind('foo', foo(...));
//

$webview->bind('foo', foo(...));

In all examples from here on, the short facade method will be used to simplify the examples.

Also, don't forget that PHP has a simple way to pass functions using first class callable syntax. Thus, a simple registration of the var_dump() function looks like this:

$app = new Boson\Application();

$app->webview->bind('var_dump', var_dump(...));

During registration, an exception FunctionAlreadyDefinedException may occur if you are trying to register a function that has already been registered.

Custom Context

You may have noticed that functions are registered globally, which is not always convenient.

To register functions in a context, you can use the dot-syntax, which allows you to register a function in a specific JavaScript context.

$app = new Boson\Application();

$app->webview->bind('example.some', $example->some(...));
$app->webview->bind('example.any', $example->any(...));

Access to such functions from the client side is also done through a dot.

example.some('hello');
example.any('world');
github discord telegram Get started Documentation Contribution Guide License Release Notes BOSON PHP © 2025. All Rights Reversed.