home/about - roadmap - docs - mailing list - downloads/cvs - sourceforge project page - links
<?php // before we create a bug, we'll need to identify ourselves $me = new User("my_email@example.org"); // create a new issue $bug = new Bug(); // <-- Note the empty () $bug->Creator($me); $bug->Title("The sink is clogged"); $note = new Comment("Hurry, it's going to over flow soon!", $me); // note that a user has to be associated with a comment if($bug->Save()) { // now we'll attach our comment to the bug $bug->AddComent($note); // we're done return (TRUE); // if we're here it means there was a problem print('<font color="red">'.$bug->GetErrorMsg().'</font>'); ?>
As you can see, the API is very simple. Creating a new "Bug" object without any parameters for it's constructor causes it to create a blank bug. You can then set the properties of the bug. Once you're complete, you can Save() the bug which will assign it an ID and set it's CreatedDate.
You can Save() changes to an existing bug if you need to, but adding a Comment or an Attachment happens immediately and requires that the Bug have an ID and therefore can only be done after the bug is saved.
Note that we created an instance of a User and we included an e-mail address as the parameter. In the default installation, the e-mail address is used as the unique ID for each user. If the e-mail address didn't represent an existing user, a new user is created. This is configurable and you can disable automatic creation of users if you want.
<?php // each bug has a unique ID, in this case, we'll look up bug #5 $bugid = 5; $bug = new Bug($bugid); $creator = $bug->Creator(); // Creator() returns a User object print("Bug $bugid created by "); print($creator->EmailAddress()); print(" on "); print($bug->CreatedDate("F j, Y")); // based on the php date() function, this example shows: // May 3, 2003 // now we'll display all the comments print("<br><br>Notes:<br>"); while($comment = $bug->GetComment()) { // $comment now is a Comment Object print($comment->CreatedDate("F j, Y, g:i a")); print("<br>"); print($comment->Print()); print("<br>"); } ?>
Displaying an issue is equally easy. The point of interest here is the GetComment() function that starts with that returns a Comment object for the first comment. If there are no comments (which is unlikely) it will return false. If a comment is returned, it increments it's pointer so that the next time it's called it will return the next comment.
Another point of interest is the CreatedDate() methods of Bug and Comment. This value works just like the php date() function except that if no params are specified, it simply returns the timestamp.