Professional WebApps

Derek Bridge

Department of Computer Science,
University College Cork

Professional WebApps

Aims: to learn what it takes to write industrial-strength webapps

More about client-side technologies

More PHP: object-oriented programming

Object-oriented PHP: a Person class definition

<?php 
class Person
{
   var $name;
   var $dob_timestamp;
	
   function __construct($name, $dob_str)
   {
      $this->name = $name;
      $this->dob_timestamp = strtotime($dob_str);
   }
	
   function get_name()
   {
      return $this->name;
   }
	
   function get_years_old()
   {
      for ($i = 0; strtotime("-{$i} year") > $this->dob_timestamp; $i++);
      return $i - 1;
   }
}
?>

Object-oriented PHP: using the Person class definition

<?php
 include 'Person.php';
 
 $hugh = new Person('Hugh Jeegoh', '12/10/1980');
 
 echo "Your name is {$hugh->get_name()} 
       and you are {$hugh->get_years_old()} years old"
?>

Object-oriented PHP: templates

An example PEAR IT template

...
<body>
 <table> 
  <!-- BEGIN row -->
  <tr>
   <td>
    {FRUIT}
   </td>
   <td>
    {PRICE}
   </td>
  </tr>
  <!-- END row -->
 </table> 
</body>

An example PHP script that uses the template


<?php
 $prices = array('Apples' => 1.59,
                 'Pears' => 2.34,
                 'Kumquats' => 4.05,
                 'Jujubes' => 2.34);

 include 'HTML/Template/IT.php';
 $tpl = new HTML_Template_IT("./templates");
 $tpl->loadTemplatefile("my_template.tpl", true, true);

 foreach($prices as $fruit => $price) 
 {
    $tpl->setCurrentBlock("row");
    $tpl->setVariable("FRUIT", $fruit);
    $tpl->setVariable("PRICE", $price);
    $tpl->parseCurrentBlock("row");
 }
 
 $tpl->show();
?>

PHP error-handling

PHP error-handling

PHP error-handling

Software reuse

Efficiency

Database efficiency

Concurrent access to databases

Other