アプリケーションオブジェクトで開発
スケルトンの作成とエントリポイントの設定
まず、基本手順にしたがって「スケルトン」と「エントリポイント」を作成・設定します、アプリケーションIDは「Frmapl」です。
『http://localhost/Frmapl/index.php』とアクセスして、正しくプロジェクトが生成されているのを確認してください。

以上で、最低限の設定が行われたアプリケーションが生成され開発準備ができました。


アプリケーションオブジェクトの作成
データベースは直接PEAR::DBではなく、アプリケーションオブジェクトを介して処理します。
(アプリケーションオブジェクトのデータベース処理にはPEAR::DBが必要です。)

準備
アプリケーションオブジェクトを作成するコマンドは下記のとおりです。

まず、プロジェクト「Frmapl」のフォルダに移動してからコマンドを入力します。

テーブル名はデータベース構成で説明した「nametable」を使います。


D:\frmapl\appにファイルFrmapl_Nametable.phpが作成されますので、データベース処理は、このファイルに記述していきます。
使う側は、このクラスを仲介してデータベースにアクセスします。

コントローラー
基本的にはコントローラー『 Frmapl_Controller.php 』に登録が必要なようですが、
私の環境では必要がありませんでした。
中身を調べると参照パス設定ですので不要です(既に設定された状態です)。

データベース設定
『 D:\frmapl\etc\frmapl-ini.php 』に接続するデータベースのDSNを定義してやります。
// 'dsn' => 'mysql://user:password@server/database', のサンプルにしたがって、
'dsn' => 'mysql://root:PASWD@localhost/personal',
と、実際の値を設定します。

尚、セキュリティを考慮してユーザ(userweb)を作成してある場合には下記のとおりに設定します。
'dsn' => 'mysql://userweb:PASWD@localhost/personal',


データベース処理を追加
データベースの読出し処理を記述して『http://localhost/Frmapl/index.php』とアクセスして、
正しく作成されていると文字化けもなく下記画面が表示されるようにします。

表示内容はデータベースに登録されている情報が表示されます。

プログラム作成
『アクション』・『ビュウ』・『テンプレート』・『アプリケーションオブジェクト』の4つが必要です。

データベース処理を作成します。
class Frmapl_NametableManager extends Ethna_AppManager
{

/*
* 一覧の取得
*
* @access public
* @return list
*/
function &getAlldata(){
$this->db->query("set names ujis");
$order = array('id' => OBJECT_SORT_ASC); //ソート条件
$ret=& $this->getObjectPropList(
'nametable', //
null, //array $keys: 取得するプロパティ一覧(nullなら全て)
null, //array $filter: 検索条件
$order, //array $order: 検索結果ソート条件
0, //int $offset: 検索結果取得オフセット
2000 //int $count: 検索結果取得数
);
if(Ethna::isError($ret)){
return $ret;
}
list($num,$list)=$ret;
return $list;
}

}
ファイル「Frmapl_Nametable.php」に上記を追加する。

下記を入力したactionファイルIndex.phpを作成。
/**
* indexアクションの実装
*
* @author {$author}
* @access public
* @package Frmapl
*/
class Frmapl_Action_Index extends Frmapl_ActionClass
{

/**
* indexアクションの実装
*
* @access public
* @return string 遷移名
*/
function perform()
{

$rtn = $this->readAlldata(); //DB読込み
if($rtn<=0){
echo("データ無しaction_Index-readAlldata=");
}
$this->af->setApp('count',$rtn);

return 'index';
}

/**
* データベース読込み
*
* @param string []
* @access public
* @return int データ数
*/
function readAlldata()
{
// AppManagerの取得
$manager=& $this->backend->getManager('nametable');

// 取得
$list=& $manager->getAlldata();

// 表示用データの生成
$newlist=array();
foreach($list as $key => $personal){
$newlist[]=array(
"id"=>$personal['id'],
"yomigana"=>$personal['yomigana'],
"name"=>$personal['name'],
"telphone"=>$personal['telphone'],
"fax"=>$personal['fax'],
"zip"=>$personal['zip'],
"address"=>$personal['address'],
"remarks"=>$personal['remarks'],
);
}
$this->af->setApp('list',$newlist);

return(count($newlist));
}


}

下記を入力したviewファイルIndex.phpを作成。
/**
* indexビューの実装
*
* @author {$author}
* @access public
* @package Frmapl
*/
class Frmapl_View_Index extends Frmapl_ViewClass
{
/**
* 遷移前処理
*
* @access public
*/
function preforward()
{
// レンダラ(Smarty)の取得
$renderer=& $this->backend->ctl->getRenderer();
// タイトル
$renderer->setProp('title','Personal WebDB');

}

}

テンプレート・ファイルindex.tplを作成。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-JP" />
<link rel="stylesheet" href="{$config.url}css/ethna.css" type="text/css" />
<title>{$title}</title>
</head>
<body>

<div id="header">
<h1>Frmapl</h1>
</div>

<div id="main">
<h3>アプリケーションオブジェクトでデータベース処理</h3>

データ数:{$app.count}
{$app.list[id]}
<table border="1">
<tr style="color:#ffffff" bgcolor="#a0a0a0">
<td>ID</td>
<td>Yomi</td>
<td>Name</td>
<td>Phone</td>
<td>Fax</td>
<td>Zip</td>
<td>Address</td>
<td>Rem</td>
</tr>
{foreach from=$app.list item=dt}
<tr>
<td>{$dt.id}</td>
<td>{$dt.yomigana}</td>
<td>{$dt.name}</td>
<td>{$dt.telphone}</td>
<td>{$dt.address}</td>
<td>{$dt.fax}</td>
<td>{$dt.zip}</td>
<td>{$dt.remarks}</td>
</tr>
{/foreach}
</table>

</div>

<div id="footer">
Powered By <a href="http://ethna.jp">Ethna</a>-{$smarty.const.ETHNA_VERSION}.
</div>

</body>
</html>