Set up Ext JS with PHP

December 18th, 2022 by Rijad Husic

Setting up Ext JS with PHP

Ext JS is a powerful JavaScript framework for building rich web applications. It provides a wide range of UI components, a robust data package, and many other features to help you create modern, interactive web applications. In this tutorial, we will show you how to set up Ext JS with PHP, so you can start building your own web applications.

Before we begin, make sure you have the following:

  • A web server with PHP installed
  • A text editor (such as Sublime Text or Visual Studio Code)
  • Ext JS downloaded and extracted to a folder on your computer

Step 1: Create a PHP Project

First, create a new folder on your computer where you want to store your PHP project. Open the folder in your text editor and create a new PHP file called "index.php".

Step 2: Include Ext JS in Your Project

Next, we need to include Ext JS in our project. To do this, add the following lines of code to the head section of your index.php file:

<link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css">
<script type="text/javascript" src="extjs/ext-all.js"></script>

Make sure to change the file paths to match the location of the Ext JS files on your computer.

Step 3: Create a Container

Ext JS uses containers to hold UI components and layout the page. To create a container, add the following code to your index.php file:

<div id="myContainer"></div>

This will create a div element with the ID "myContainer" that we can use to hold our UI components.

Step 4: Add a UI Component

To add a UI component, such as a button or grid, you will need to use Ext JS's JavaScript syntax. For example, to add a button to the container we created earlier, add the following code to your index.php file:

Ext.onReady(function() {
  Ext.create('Ext.Button', {
    text: 'Click Me',
    renderTo: 'myContainer',
    handler: function() {
      alert('You clicked the button!');
    }
  });
});

This code creates a button with the text "Click Me" and adds it to the "myContainer" div. When the button is clicked, it will display an alert message.

Step 5: Test Your Project

To test your project, save the index.php file and open it in your web browser. You should see the button you created and be able to click it.

Congratulations, you have successfully set up Ext JS with PHP! With these basic steps, you can now start building more complex and interactive web applications using the Ext JS framework.