This post contains two examples of Adapter Design Pattern using PHP. I am giving these examples in order to understand more comprehend about Adapter Pattern.
First, implementation of Adapter Design Pattern statement
Convert the interface of a class into another interface clients expect.
Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.
Adapters are helpful if you want to use a class that doesn’t have quite the exact methods you need.
Second, implementation of using legacy class and you can’t change that legacy class but you want to port its method to another needful method.
An example class ‘clsProducts’ methods can be used inside many Adapter class to returns another result.
clsProducts object instance is passed as Adapter classes constructor argument and clsProducts methods are being used inside those Adapter classes.
We can create PDF file using PHP easily. I choose mPDF in order to do this. Why mPDF ? That because the method is to use html string for writing PDF content and then produce PDF as an output.
We can format PDF content like an HTML page i.e using bold <b/>, table <table/>, etc which is easy for Web developer off course.
PHP.Net has own recommended PDF creation class which are Haru PDF and PDFLib. They are great but many lines and methods to do simple ‘Hello World’ example. I feel easier using mPDF since it uses HTML string.
This blog post will demonstrate how to install and gives some basic examples so reader can have brief ideas how to create PDF programmatically.
Download & Install MPDF
Download PHP source code of MPDF from http://www.mpdf1.com/mpdf/index.php?page=Download
Copy to a folder in your web server directory. I am using MPDF57 for this demonstration.
Any table like objects like array and recordset have same structure. They have rows and columns.
Usually column is a key and row is a value.
A recordset that comes from database ‘select’ operation usually stored in array or OOP object variable on MVC concept or any kind of business logic and view layer.
A web page access this variable to show its data. View layer only include database and datatable class files. So web page users doesn’t access database operational directly.
With this concept, I have build a simple DataTable class to store those kind of objects.
This DataTable has functions to add columns and rows and get their values so that we can extract information from DataTable with easy and use same methods repeatedly.
Also we can get DataTable object value on another page with SESSION functionality.
Posted in PHP
Tagged DataTable, DB2, db2_close, db2_connect, db2_fetch_array, OOP, PHP, PHP Example, PHPExcel, session, web paging
Many ways to create a progress bar but in this blog post I give example on PHP Progress bar built with OOP.
The reason I use OOP is that the class can be used again for any purpose which need progress bar.
We need interface OOP object which contains three methods which are
get_max() returns maximum value that progress bar will have,
get_progress() returns current progress value or progress percentage. This progress percentage value sets progress bar value and
do_work() to do a real work like database or files operation or else.
I use JQuery to draw Progress Bar in User Interface because of simplicity to make it with JQuery. I assume that you already know basic of progress bar and JQuery.
In programming languages, polymorphism means that some code or operations or objects behave differently in different contexts.
It able to process objects differently depending on their data type or class. More specifically, it is the ability to redefine methods for derived classes.
So it is overloading parent object. Child objects has all methods in their parent and childs can have more methods.
Several parent object type to support polymorphism are class, abstract and interface. In this post, I use ‘abstract’ class as parent to give polymorphism demo due to I will using it as wrapper class.
What I mean of wrapper class is I do not have to write same code over and over again in every child classes. I only have to write once in the abstract functions.
Abstract class can not have an instance or real object. It is only model of the class design but the different from ‘interface’ that abstract can have a body inside function declaration.
To explain the differences between abstract, interface and general class, look at code below: Continue reading
Retrieving large recordset contains so many rows on web page will consume a lot of resources both server and client. Responsiveness of web page decreasing.
We need to retrieve that recordset part by part and display it using web paging method. In my previous post about Limiting DB2 Record Number I had show sql example to limit large recordset on SAMPLE Database.
This php example show employee’s related project:
Many organizations use multi database software. For example an organisation’s HRD system using SQL Server and on its ERP they use DB2.
To develop an application that can connect to DB2 and SQL Server using PHP, we need database-independent connection object.