Friday, December 08, 2006

Simpl Join()!

Its amazing how much code can be reduced by using a framework, especially a framework that accomplishes all the most basic elements without interfering with usability. With Simpl we are trying to accomplish just that. So we recognized the problem of information being in two different tables and having two queries just was not cutting it. So we are proud to announce the Join() function in DbTemplate. This is now integrated into the examples also to get you up and running with it.

Here is a sample code snipit of joining the Registration, User and Payments tables to view information all in one list with one query:
// Create the Registration class
$myRegistration = new Registration;
$display[] = array('registration_id','user_id','date_registered','guests');

// Create the User Class
$tmpUser = new Users;
$myRegistration->Join($tmpUser, 'user_id', 'INNER');
$display[] = array('first_name','last_name');

// Create the Payments Class
$tmpPayment = new Payment;
$myRegistration->Join($tmpPayment, 'conference_id', 'INNER');
$display[] = array('conference_id', 'amount', 'status', 'method');

// Get a list of all the Registrations
$myRegistration->GetList($display,'date_registered','DESC');

Questions or Concerns? Head over to our Simpl Group.

Just added, Output individual fields

So PHP Simpl does a good job of outputting an XHTML form with very extend able features such as labels, required *'s, size and maxlength calculation, example and error output automatically. But have you ever just wanted to output the form in your own way? Well now you can, this can be accomplished with the FormField() function inside the DbTemplate class. It handles all that same great XHTML formatting, you just have to worry about where you want to flied to be displayed.

Function Prototype:
public function FormField($field, $hidden=false, $options='', $config='');

Example:
$myPost = new Post;
$hidden = false;
$options = array();
$config = array();

echo '<form>';
$myPost->FormField('title', $hidden, $options, $config);
echo '<input name="submit" value="Save" type="submit">';
echo '</form>';