Switch PHP Class Overview

The Kendo UI Switch for PHP is a server-side wrapper for the Kendo UI Switch widget. It is used to display two exclusive choices.

Getting Started

Configuration

Below are listed the steps for you to follow when configuring the Kendo UI Switch for PHP.

Step 1 Make sure you followed all the steps from the introductory article on Telerik UI for PHP—include the autoloader, JavaScript, and CSS files.

Step 2 Create a Switch.

Example
<?php
  $switchButton = new \Kendo\UI\SwitchButton('switch');
?>

Step 3 Output the Switch by echoing the result of the render method.

Example
<?php
echo $switchButton->render();
?>

Event Handling

You can subscribe to all Switch events.

Specify Function Names

The example below demonstrates how to subscribe for events by specifying a JavaScript function name.

Example
<?php
$switchButton = new \Kendo\UI\SwitchButton('switch');

// The 'switch_change' JavaScript function will handle the 'change' event of the switch
$switch->change('switch_change');

echo $switchButton->render();
?>
<script>
function switch_change() {
    // Handle the change event
}
</script>

Provide Inline Code

The example below demonstrates how to subscribe to events by providing inline JavaScript code.

Example
<?php
$switchButton = new \Kendo\UI\SwitchButton('switch');

// Provide inline JavaScript code that will handle the 'change' event of the switch
$switchButton->change('function() { /* Handle the change event */ }');

echo $switchButton->render();
?>

Reference

Client-Side Instances

You are able to reference an existing Switch instance via the jQuery.data(). Once a reference is established, use the Switch API to control its behavior.

Example
<?php
$switch = new \Kendo\UI\Switch('switch');
echo $switch->render();
?>
<script>
$(function() {
    // The constructor parameter is used as the 'id' HTML attribute of the switch
    var switch = $("#switch").data("kendoSwitch");
});
</script>

See Also

Other articles on Telerik UI for PHP and on the Switch:

In this article
Not finding the help you need? Improve this article