OOUI/PHP examples

There is a more extensive set of examples in the source code repository.

If you are using OOjs UI in a mediawiki extension, see ../Using_the_library_with_extensions.

If using the OOjs UI library in a standalone PHP project, run.

You may also wish to clone the repo and/or install it using composer, then take a look at. This provides concrete examples of using most of the widgets from PHP code.

Creating a button
To create a button, use the  class. The first and only argument to a button's constructor is its configuration.

Before the button is converted to HTML and emitted, the label, target and href can be changed using the  and   methods.

The button is now created, and has a label which reads "Still click me!", but is not yet visible to the user, as it must first converted to HTML and echoed into the document:

Adding JavaScript behaviors
Setting the  property will ensure that clicking the button loads a new PHP page. But if you want to use the technique of progressive enhancement to add client-side JavaScript behaviors to the button, you can "infuse" the object on the client side with the JavaScript OO.ui.infuse method. You must set an  attribute on the widget from PHP and also set the   property when the widget is configured: Then you'd load some client-side JavaScript to enhance this widget:

Playing it safe
For extra type safety, you can use the  method of the specific type of widget you expect. That is:

This will throw an exception at runtime if PHP and JavaScript disagree about the widget type of.