| Current File : //opt/RZphp5/includes/doc/HTML_Progress2/docs/TDG/ch16s05.html |
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>
Custom Error Message Generation
</title>
<link rel="stylesheet" href="book.css" type="text/css" />
<meta name="generator" content="DocBook XSL Stylesheets V1.69.1" />
<link rel="start" href="index.html" title="HTML_Progress2 Manual" />
<link rel="up" href="ch16.html" title=
"Chapter 16. Error Handler" />
<link rel="prev" href="ch16s04.html" title="Error Context Display " />
<link rel="next" href="ch17.html" title=
"Chapter 17. Events to observe" />
<style type="text/css">
/*<![CDATA[*/
body {
background-color: white;
color: black;
}
:link { color: #0000FF }
:visited { color: #840084 }
:active { color: #0000FF }
div.c2 {font-family: monospace;}
h2.c1 {clear: both}
/*]]>*/
</style>
</head>
<body>
<table class="progress2Header">
<tr>
<td>
<img src="img/pear_progress2.gif" align="left" alt=
"PEAR Progress2 logo" />
<h1>
HTML_Progress2 : The Definitive Guide
</h1>
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr>
<th colspan="3" align="center">
Custom Error Message Generation
</th>
</tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="ch16s04.html">Prev</a>
</td>
<th width="60%" align="center">
Chapter 16. Error Handler
</th>
<td width="20%" align="right">
<a accesskey="n" href="ch17.html">Next</a>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
<div class="sect1" lang="en" xml:lang="en">
<div class="titlepage">
<h2 class="title c1">
<a name="id4804070" id="id4804070"></a>Custom Error Message
Generation
</h2>
</div>
<div class="toc">
<dl>
<dt>
<span class="sect2"><a href="ch16s05.html#id4804100">Option:
message_callback</a></span>
</dt>
<dt>
<span class="sect2"><a href="ch16s05.html#id4804127">Option:
context_callback</a></span>
</dt>
</dl>
</div>
<p>
In the default error class <code class=
"classname">HTML_Progress2_Error</code> there are two methods designed
for use with generating error messages efficiently. To use them, you
must set the options <code class="literal">message_callback</code>, and
<code class="literal">context_callback</code>.
</p>
<div class="sect2" lang="en" xml:lang="en">
<div class="titlepage">
<h3 class="title">
<a name="id4804100" id="id4804100"></a>Option: message_callback
</h3>
</div>
<p>
The default message handling callback (<code class=
"methodname">HTML_Progress2_Error::_getErrorMessage</code>) get an
array mapping error codes to error message templates, like so:
</p>
<div class="php c2">
<ol>
<li class="li1">
<div class="de1">
<span class="kw2"><?php</span>
</div>
</li>
<li class="li1">
<div class="de1">
<span class="re1">$messages</span> <span class="sy0">=</span>
<span class="kw3">array</span><span class="br0">(</span>
</div>
</li>
<li class="li1">
<div class="de1">
HTML_PROGRESS2_ERROR_UNKNOWN <span class=
"sy0">=></span>
</div>
</li>
<li class="li1">
<div class="de1">
<span class="st0">'unknown
error'</span><span class="sy0">,</span>
</div>
</li>
<li class="li1">
<div class="de1">
HTML_PROGRESS2_ERROR_INVALID_INPUT <span class=
"sy0">=></span>
</div>
</li>
<li class="li1">
<div class="de1">
<span class="st0">'invalid input,
parameter #%paramnum% '</span>
</div>
</li>
<li class="li1">
<div class="de1">
<span class="sy0">.</span> <span class=
"st0">'"%var%" was expecting '</span>
</div>
</li>
<li class="li1">
<div class="de1">
<span class="sy0">.</span> <span class=
"st0">'"%expected%", instead got "%was%"'</span>
</div>
</li>
<li class="li1">
<div class="de1">
<span class="br0">)</span><span class="sy0">;</span>
</div>
</li>
<li class="li1">
<div class="de1">
<span class="kw2">?></span>
</div>
</li>
</ol>
</div>
<p>
Basically, if a variable name is enclosed in percent signs (%), it
will be replaced with the value passed in the associative array.
</p>
</div>
<div class="sect2" lang="en" xml:lang="en">
<div class="titlepage">
<h3 class="title">
<a name="id4804127" id="id4804127"></a>Option: context_callback
</h3>
</div>
<p>
The default context handling callback (<code class=
"methodname">HTML_Progress2_Error::getBackTrace</code>) gets an array
of execution functions and discovers where the error was generated.
</p>
</div>
</div>
<table class="progress2Footer">
<tr>
<td align="left">
HTML_Progress2 : The Definitive Guide
</td>
<td align="right">
v 2.4.0 : April 20, 2007
</td>
</tr>
</table>
<div class="navfooter">
<hr />
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="ch16s04.html">Prev</a>
</td>
<td width="20%" align="center">
<a accesskey="u" href="ch16.html">Up</a>
</td>
<td width="40%" align="right">
<a accesskey="n" href="ch17.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">
Error Context Display
</td>
<td width="20%" align="center">
<a accesskey="h" href="index.html">Home</a>
</td>
<td width="40%" align="right" valign="top">
Chapter 17. Events to observe
</td>
</tr>
</table>
</div>
</body>
</html>