You are on page 1of 10

PHPMaker is a PHP code generator.

You can make a pretty complex web application with


PHPMaker without writing a single line of code. PHPMaker generates clean code and is useful
when you need a web app that heavily relies on a database. Coding a database driven website
is more difficult than it sounds. Instead of reinventing the wheel, well rely on PHPMaker to do
the hard work for us.

Things which we can do with PHPMaker is only limited by our

understanding of the generated code. The menu, for example, is on the left by default which
you cannot change through PHPMaker, but you can manually edit the generated code and
position the menu to the top.
Well be making a simple web application for a library. Members will be able to search the
library catalogue and list books by categories. Staffs will be able to add/edit/remove books as
well as register/deregister members.
You will need XAMPP to try out the app.
You must create a database with your tables first. Open phpMyAdmin and write out your
MySQL statements. In our case we need to create two tables:
CREATE TABLE books (
book_idint(8) primary key auto_increment,
titlevarchar(50) not null,
authorvarchar(50) not null,
covervarchar(100)
)
CREATE TABLE users (
user_idint(8) primary key auto_increment,
usernamevarchar(20) not null,
passwordvarchar(20) not null,
user_levelint(2) default 0,
loanedint(8) references books(id)
)

Every time youre working on PHPMaker, youll need to have XAMPP running.
Open PHPMaker and connect to the database.

Normally, the username should be root and the password field should be left empty. You can
always change that through phpMyAdmin for extra security. When you click on the Connect
button, you should see your two tables appear in the left panel.

User Login

Since, our app will require login, we need to set this up. Head over to the security tab.
Remember that members details will be stored in the users table. PHPMaker needs to know
that along with the names of columns for the username and password.

We are not done yet. We need to click on the Advanced button to set up additional user login
options.

The settings are self-explanatory. You might not check all of them, but user registration should
at least be enabled. Well come back to this later when well have to set permissions on who
can or cannot view/edit table and views.

Generating
Before generating the app, ensure that XAMPP is running. Set the application root folder to that
of XAMPP www folder. If you want PHPMaker to automatically open your browser after
generation, set the following option:

After generation, you will be presented with a login screen. You might not see the tables now
as you have not yet set permissions for user levels.

Adding Menu Items


Since books are classified in different categories, we need a menu item for each category. In
PHPMaker, tables and views make up menu items. In our case, we need views. Results of
select queries on tables are called views. Views are dynamic and they changed depending on
the data currently in the table.
We will create five views for now for five categories of books:
1.
2.
3.
4.
5.

Crime
Fantasy
Humor
Horror
Travel

Right-click on the View option is the left panel, and select Create View from the context menu.

We need to write SQL statements for each view. Here the view will consist of all crime books.
Dont forget to give it a name. Repeat the same procedure of the other categories.
In the end, well obtain this:

PHPMaker lets you specify what kind of html tags each column of a table/view is generated
into. Since each book has a cover, we need to provide image upload/preview functionality.
Set an upload folder from the PHP tabbed menu:

Then select the cover column:

Change the View tag to IMG and the Edit tag to file as follows:

What this does is display the cover when the table books is listed. Do the same for the views.

Arranging menu items


The Menu Editor from the tools menu lets you change the label for menu items, change it
appropriately.

You can make hierarchical menus too.

Setting permissions
Obviously, a normal user should not be allowed to do edit/add operations on some tables. If
you remember, theres a user_level column in table users. By default,we made it zero.
PHPMaker has two built-in user levels (you can more): -1 and 0.
-1 is for administrator. 0 is the default. When a user registers, hes assigned 0 by default. Staff
will have their user level upgraded to -1 by the database administrator.
Here we have set list/search/view permissions for members.

Generating a blank page


You can generate a blank page which you can fill with a welcome note for example. You can set it to be
the default page that will be opened when you open the app.

PHPMaker always generates a blank page named blankpage.php. Since youve entered the Start page
as being home.php, you must rename blankpage.php to home.php so PHPMaker can find and open it
the next time. If you make some changes to your project and generate again, your home.php will not be
overwritten. Look for it in the destination folder.

10

You might also like