NAME
Apache::PageKit::Model - Base Model Class
DESCRIPTION
This class provides a base class for the Modules implementing the backend business logic for your web site.
This module also contains a wrapper to HTML::FormValidator. It validates the form data from the Apache::Request object contained in the Apache::PageKit object.
When deriving classes from Apache::PageKit::Model, keep in mind that all methods and hash keys that begin with pkit_ are reserved for future use.
SYNOPSIS
Method in derived class.
sub my_method {
my $model = shift;
# get database handle, session
my $dbh = $model->dbh;
my $session = $model->session;
# get inputs (from request parameters)
my $foo = $model->input_param('bar');
# do some processing
...
# set outputs in template
$model->output_param(result => $result);
}
METHODS
The following methods are available to the user as Apache::PageKit::Model API.
- input_param
-
Gets requested parameter from the request object
$apr
.my $value = $model->input_param($key);
If called without any parameters, gets all available input parameters:
my @keys = $model->input_param;
Can also be used to set parameter that Model gets as input. For example you can set the userID when the user gets authenticated:
$model->input_param(pkit_user => $userID);
- output_param
-
This is similar to the HTML::Template method. It is used to set <MODEL_*> template variables.
$model->output_param(USERNAME => "John Doe");
Sets the parameter USERNAME to "John Doe". That is
<MODEL_VAR NAME="USERNAME">
will be replaced with "John Doe".It can also be used to set multiple parameters at once by passing a hash:
$model->output_param(firstname => $firstname, lastname => $lastname);
Alternatively you can pass a hash reference:
$model->output_param({firstname => $firstname, lastname => $lastname});
- content_param
-
Similar to
output_param
but sets content variables associated with the <CONTENT_VAR> and <CONTENT_LOOP> tags. - apr
-
Returns the Apache::Request object.
my $apr = $model->apr;
- dbh
-
Returns a database handle, as specified by the
MyPageKit::Model::dbi_connect
method.my $dbh = $model->dbh;
- session
-
Returns a hash tied to <Apache::PageKit::Session>
my $session = $model->session;
- pkit_message
-
Displays a special message to the user. The message can displayed using the
<PKIT_LOOP NAME="MESSAGE"> </PKIT_LOOP>
code.You can add a message from the Model code:
$model->pkit_message("Your listing has been deleted.");
To add an error message (typically highlighted in red), use
$model->pkit_message("You did not fill out the required fields.", is_error => 1);
- pkit_set_page_id
-
Sets the page_id. This is usually used "redirect" to different template.
$model->pkit_set_page_id($page_id);
- pkit_validate_input
-
Takes an hash reference containing a HTML::FormValidator input profile and returns true if the request parameters are valid.
# very simple validation, just check to see if name field was filled out my $input_profile = {required => [ qw ( name ) ]}; # validate user input unless($model->pkit_validate_input($input_profile)){ # user must have not filled out name field, # i.e. $apr->param('name') = $model->input_param('name') is # not set, so go back to original form $model->pkit_set_page_id('orig_form'); return; }
The following methods should be defined in your MyPageKit::Common module:
- pkit_dbi_connect
-
Returns database handler,
$dbh
, which can be accessed by rest of Model through$model->dbh
. - pkit_session_setup
-
Returns hash reference to session setup arguments.
- pkit_auth_credential
-
Verifies the user-supplied credentials and return a session key. The session key can be any string - often you'll use the user ID and a MD5 hash of a a secret key, user ID, password.
- pkit_auth_session_key
-
Verifies the session key (previously generated by
auth_credential
) and return the user ID. This user ID will be fed to$model->input_param('pkit_user')
.
SEE ALSO
Apache::PageKit, HTML::FormValidator
AUTHOR
T.J. Mather (tjmather@anidea.com)
COPYRIGHT
Copyright (c) 2000, AnIdea Corporation. All rights Reserved. PageKit is a trademark of AnIdea Corporation.
LICENSE
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Ricoh Source Code Public License for more details.
You can redistribute this module and/or modify it only under the terms of the Ricoh Source Code Public License.
You should have received a copy of the Ricoh Source Code Public License along with this program; if not, obtain one at http://www.pagekit.org/license