NAME

DBIx::HTMLView::Post - A post in a DBI database

SYNOPSIS

$post=$post_set->first;
print $post->view_html;   # View a post

$post->set('testf', 7);   # Set the testf field to 7
$post->update;            # Update the databse with the modified post

$post=DBIx::HTMLView::Post->new($tab)   # Create a new post
$post->set('testf', 7);   # Set the testf field to 7
$post->update;            # Insert the new post in the databse

DESCRIPTION

This object represenets a single post in a specifik table in the database. It has methods to view post as well as to modify it's data and to reflect those modifications in the database.

$post=DBIx::HTMLView::Post->new($tab, $data, $sth)

Creats a new post belonging to the table $tab (a DBIx::HTMLview::Table object). $data and $sth is used to initiale the post with it's fields, which can be done in several ways:

1. To create a new empthy post with no data set, simply don't specify those arguments. 2. If $data is an array reference, $sth is supposed to be the object returned by a DBI execude call with a select command, and $data should be the array ref with the data you want to create a post object of. 3. If $data is a hash reference, it is supposed to contain Fld/Value pairs. 4. If $datat is CGI object the CGI params is supposed to be Fld/Value pairs. Note that relations in this case is defined by setting the name of the relation to the id's of the posts related to, eg it will be defined once for every post.

$post->set($fld, $val)

Set's the Fld named $fld to $val. If $val is not a DBIx::HTMLView::Fld object $post->tab->new_fld($fld,$val) is called to create the Fld object to represent this fld and it's data.

For fields data ($val) is specified as a string or as the first item of a array referenced to by $val. Relations are represented as a reference to an array of the id's of the posts being related to.

$post->got_fld($fld_name)

Returns true if we have data specified for the fld named $fld_name.

$post->view_text

Returns a string that could be used to view this post in text format

$post->view_html

Returns a string that could be used to view this post in html format.

$post->fld_names

Returns an array of the fld names currently specified in this post, use $post->tab->fld_names to list all Fld of the post.

$post->fld($fld_name) =head2 $post->val($fld_name)

Returns the Fld representing that data of the Fld named $fld_name.

$post->tab

Returns the table this post belongs to (a DBIx::HTMLView::Table object).

$post->got_id

Returns true if the id of this post is defined, which is the same as that the post is represented in the databse as well (which is not true for new posts that not yet have been added to the datbase, using $post->update).

$post->id

Returns the id of this post or dies with "No id defined" if it is not defined. Se $post->got_id.

$post->update

Updates the database with the data found in this object or creats a new post in the database with that data if the id is not defined. Se $post->got_id.