23
Mon, Dec
1 New Articles

Jazz Up Your Web Site by Customizing PHP Templates

Web Languages
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Implement the latest Web 2.0 bells and whistles so that you can provide not only the prettiest but also the smartest Web apps!

 

It's an axiom of human nature that people generally appreciate beautiful things more than plain ones. This is true of Web applications compared to 5250 applications, too. Although many of us die-hard green-screen fans may extol the virtues of green-screen apps for their ease of use and simplicity, they just don't look as pretty as good Web applications. Of course, prettiness and intelligence don't always go hand in hand, as seems evident by the notorious behavior of a certain hotel heiress. In the case of Web development, though, it is possible to produce applications that are at once functionally powerful and pretty.

 

There are a couple of approaches you can take to Web development:

1. Approach it like writing RPG code with SEU: Write every page from scratch, probably by copying in common pieces of user interface code and business logic, tweaking areas of the code that need customizing, and then adding more complex logic.

2. Use a unified approach, where business rules, overall look and feel of the application, UI design components, etc. are built up front, and all application details use these foundation components.

 

The first approach is probably what most System i developers are used to. We rarely write entire programs from scratch. Instead, we copy in an existing source member and modify key parts of it (file names, key lists, etc.) to create a new set of functionality for the application. This is really template programming in its crudest form. It relies on  the developer's memory to recall all the necessary places where code must be customized and his skills to write the correct customization code. 

 

The next level of sophistication involves using an application development tool that does the memory and skills work for you. For example, there are System i development tools that prompt a developer for all the required information to produce working programs, without requiring any programming knowledge at all. However, one of the weaknesses to this style of development is that it is not productive when handling application-wide changes. For example, with Web applications, it's not uncommon for companies to change their corporate image frequently, either with different color schemes, new logos, or things such as rounded corners on boxes instead of straight edges. Most recently, the rise in adoption of AJAX technology has meant an entirely different way for Web apps to interact with users.

 

In contrast, the second approach lends itself well to system-wide changes. By using templates up front, you can afford to invest time in isolating those components of an application that are most likely subject to change and work on customizing them. You can design your templates so that these components are accessed dynamically, at run time, from a central source. This gives you the ability to easily apply system-wide changes, simply by installing new versions of these commonly used components. 

Open-Source Templates and Frameworks

 

In the PHP world in general, there are several products that use templates in this manner.  For example, Zend Frameworks makes use of the Model-View-Controller (MVC) design approach and utilizes templates extensively. You can think of Zend Frameworks as consisting of a set of loosely coupled, powerful UI/code components that encapsulate lots of PHP code to implement commonly used functionality. For example, there are Frameworks that support AJAX implementation, PDF generation, and email capabilities.

 

These components can be aggregated into templates that can significantly reduce the number of steps a programmer has to go through to produce an application compared to traditional coding. However, one weakness of this approach is that the framework components are not tightly integrated with the Zend IDE. This means you don't get codeless wizards for integrating Zend Frameworks components. Instead, you have to write a couple of lines of code manually. This is not too big a deal, but anything that helps a developer's productivity is always desirable, and minimizing manual coding is generally helpful in this regard. Another thing you should know about Zend Frameworks is that it relies heavily on object-oriented concepts, which may still be somewhat daunting to RPG programmers.

 

Smarty is another tool that is designed to provide the benefits of  PHP development using templates. According to the Smarty Web site, "One of Smarty's primary design goals is to facilitate the separation of application code from presentation. Typically, the application code contains the business logic of your application, written and maintained in PHP code." The example provided at this URL shows how Smarty simplifies programming a page that produces a list of records from a database table

 

Here is an example of a skeleton template that loops through a list of articles and displays them in a table:

 

<table>

   {section name=art loop=$article}

      <tr>

         <td>{$article[art].headline}<td>

         <td>{$article[art].date}<td>

         <td>{$article[art].author}<td>

      </tr>

   {/section}

</table>

 

The output may look something like this:

 

<table>

   <tr>

      <td>How the west was won<td>

      <td>Dec 2, 1999<td>

      <td>John Wayne<td>

   </tr>

   <tr>

      <td>Team loses, Coach quits<td>

      <td>Feb 2, 2002<td>

      <td>John Smith<td>

   </tr>

   <tr>

      <td>Gourmet Cooking<td>

      <td>Jan 23, 1954<td>

      <td>Betty Crocker<td>

   </tr>

</table>

 

Normally, the PHP programmer would have to code a loop, along with some MySQL table access code, to produce a list. Smarty simplifies this by greatly minimizing the coding effort. Smarty is not tied to any particular PHP development tool, such as Zend,'s IDE, Eclipse, or WebSmart PHP. Like Zend Frameworks, you need to include a couple of lines of code in your application in order to plug in Smarty, as well as install it on your server.

 

Another open-source framework available for PHP is CakePHP. There's a great tutorial on CakePHP available at IBM's developerWorks site.

 

CakePHP is conceptually very similar to Zend Frameworks. It also relies heavily on the MVC approach to development, separating the user interface from the back-end logic. It's also heavily object-oriented. It uses three major categories of object classes: Model for the backend logic, View for the user interface/design/page appearance, and Controller for the messaging mechanism that communicates between the Model and the View. The Controller class utilizes AJAX functionality, for example, to handle conversations between the View and the Model. CakePHP also includes Helpers, which are shorthand coding constructs for building components. For example, the table Helper builds a table of values to display in a page with lots of functionality, using one line of code.   

 

Again, because CakePHP is not tied to any particular IDE, you still have to learn the tool and write code in it to benefit from its productivity gains. However, you can get considerable functionality with minimal code (compared to hand-writing PHP) by using CakePHP.

 

CodeIgnitor is yet another open-source PHP-based Frameworks tool. It also has a large collection of helper functions and other template-based components very similar to CakePHP and  Zend Frameworks. If you are interested in further researching the concepts behind these tools, you should also read about Ruby on Rails. While Ruby is a completely different language from PHP,  Rails uses the same Frameworks concepts. There are many good books that explain Rails.

CRUD Is Beautiful

One thing that many template-driven and frameworks software solutions provide is CRUD functionality. CRUD stands for Create, Read, Update, and Delete and is really just another shorthand for what System i developers commonly call the "Work With" function. Most CRUD templates provide standard functions such as the ability to list records in a table, ability to page through large datasets (R for Read), ability to add records to a table (C for Create), and ability to Update and Delete records, either individually or in sets.

 

Frameworks software such as  Zend Frameworks, CakePHP,  and Ruby on Rails all provide this kind of functionality. One advantage of using these CRUD components is that you don't have to reinvent the wheel. Trying to translate the functionality of a green-screen Work With subfile program into a Web-based equivalent can be difficult, since the two underlying technologies are so different. Using CRUD components gives you a baseline for your development efforts, a starting point provided for you that can sometimes contain the equivalent of many months of research and development. 

Web 2.0 Applications: More Than Just Server-Side Code

Modern Web applications (those written in the last three years!) utilize Web 2.0 technologies extensively. Any System i-based Web applications you write now should take into account these technologies. For example, the Gmail method of returning a dynamic list of search results as a user types in the search field is now almost a standard for many apps. These interfaces rely heavily on AJAX, which in turn requires considerable JavaScript code. The importance of JavaScript is often underrated. In my own Web development efforts, I often find I'm spending more time writing client-side code than server-side code. That's also the experience many of our clients have. Luckily, I recently discovered a software library that's made my life a lot easier. It's called JQuery. The name does not reflect its purpose. It's neither a query language nor a query tool. It's really a client-side framework and a set of loosely coupled components with helper functions (sound familiar?). It hides a lot of the complexity of JavaScript programming and ensures that pages are cross-browser-compliant. There are many JQuery plugins available, such as a datagrid component that encapsulates much of the functionality you'd expect to find in a Windows database application. JQuery is open source and available under the very liberal MIT license. It is being used by some high-powered sites, such as Dell, Google, Oracle, Intuit, Bank of America, and Barack Obama! Note that JQuery does not depend on PHP as the server-side language. You can use it with any language, including RPG CGI. However, if you do make the decision to use PHP for development, you should also consider using JQuery for your  client-side development efforts because using it will definitely improve your productivity. I'll be discussing JQuery more in an upcoming article in iTechnology Manager next month.

System i Vendor Solutions

Many System i vendors have had products for quite a while that utilize many of the concepts in this article. For example, template-driven programming has been around for a long time. If you are considering PHP development, look for a product that not only has templates but also allows you to create or customize them and that integrates the templates into the IDE. This allows you to do template-driven development with a minimum of coding effort.   

Get Jazzy!

Templates and frameworks can jazz up your Web sites by providing additional functionality compared to writing by hand. In addition, templates can help you make system-wide changes to your site easily, extending the life of your applications. Frameworks, whether PHP-based or JavaScript-based, can also help you implement the latest Web 2.0 bells and whistles so that you can provide not only the prettiest but also the smartest Web apps!

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: