https://all-learning.com/php-array-indexed-associative-and-multidimensional/

Creating of PHP Portlet isn’t an easy mission as no standard specification created for. However, when it comes to make an integration between PHP and Java you may mainly would like to:

  • Execute Java code inside a PHP pages. (Using of Java Bridge, To be Discussed Later On).
  • Execute a PHP page by a Java-based container (JVM). (Using of Quercus Library).

Actually, this tutorial is intended to cover the second choice as the first one would be discussed later on. Practically, you may find a links inside Apache Pluto site referring for PHP bridge, but unfortunately, it’s considered as obsolete API, thus is no longer available. You won’t be able to locate any of these mentioned libraries neither as a JAR nor as a Maven libraries.

This tutorial will provide you a kind of integration that you may find it very helpful way to leverage a PHP code inside your Portlet application. We’re going to orchestrate the Portlet, Servlet and PHP pages for achieving employee registration process like we did in Developing Portlets with JSPs & Servlets Tutorial.

For executing a PHP pages inside a JVM, we’ve used a Quercus library which is considered as a Java-based implementation for PHP language. It’s already contained for a lot of PHP modules and extensions like PDF, MySQL, JSON, etc.

However, the assumed employee registration example will adhere the MVC concept while it handles the client request by using Standard Portlet and delegate it into the desired view (PHP pages), once the user has activated a registration action, the submitted form should be handled by the business Servlet that’s already created for this purpose and the employee should be registered after then.

A confirmation message should be displayed once the registration operation finished successfully. In case you’ve got an exception, an error message should be displayed contained for the reason of happened error.

Either the operation has been finished successfully or not, the user will be able to navigate again into the registration employee view for another trial.

Employee Table

This section will show you the Employee Table that’s used for retaining the registered employees.

Employee-Table (4)

employee.sql

Employee Model

Accordingly, an Employee object model should be defined for holding the employee’s information that’s going back and forth in the registration process.

Employee.java

PHP Views

Similar for the example was provided for JSP, the view should be handled by using a set of PHP pages. Mainly, we have a three different views, employee registration, success confirmation and failure confirmation are the only views you would deal with for handling the employee registration process.

register.php

success.php

failure.php

Just, want you notice that we have a PHP code snippets in the provided views and these will absolutely be handled by the used JVM (i.e. Apache Pluto).

Portlet Deployment Descriptor

Find below the portlet.xml file that would help your Portlet container recognize your Portlets.

portlet.xml

As you’ve mentioned, no additional fragments used as being the developed Portlet is a standard one.

Register Employee Portlet

RegisterEmployeePortlet.java

Register Employee Servlet

RegisterEmployeeServlet.java

Deployment Descriptor & Maven Build File

As we’ve stated earlier, Quercus is used for interpreting the PHP code inside your JVM, thus, below Maven file will be included for the all needed libraries that you need for executing a PHP code inside your JVM.

pom.xml

You should notice that you are provided resin library that would be used for interpreting PHP purpose. Actually, a QuercusServlet will do that and so, you must configure it inside your web deployment descriptor. So we added it inside our deployment descriptor that should look like below:

web.xml

As you’ve noticed, any request for a PHP resources should trigger the Quercus Servlet to handle the initiated request. This Servlet will read the requested resource and make its interpretation operation to return a pure HTML code for your browser.

EmployeeDAO and ConnectionUtility

For seeking simplicity, we’ve developed EmployeeDAO and ConnectionUtility classes for handling all database operations.

ConnectionUtility.java

EmployeeDAO.java

Employee Registration Demo

Now, it’s time to see what’s the result of code developed above, but before getting into, you should create a Portal page named JournalDev and you must deploy your WAR into your Apache Pluto Portlet container after then. If you’ve not tried that before, it’s important for you to return back into our Apache Pluto Introduction to know how you can achieve these important tasks.

And when you try to register another employee with the same ID, you should face the following error:

Summary

Apache Pluto hasn’t provided you the way in which you can integrate your PHP views with its Portlet container. This tutorial is a good trial from JournalDev to make this possible by orchestrate different parties help you achieving that. Contribute us by commenting below and find downloaded source code.

By admin

Leave a Reply