kazpgmの日記

『プログラム自動作成@自動生成』作成の日記

TOOL更新_ベースになるサンプルを作成中

TOOL更新_ベースになるサンプル(http://kazpgm.ddo.jp/kaz01u/admin/ではいって、「ログイン情報一覧(Logininfoテーブル用画面)」http://kazpgm.ddo.jp/kaz01u/admin/logininfo/logininfo.php?mode=listをZendFramework php5.3にリメイク)を作成中。

リメイクもローカル環境で、とりあえず動くというとこまで来ている・・・まあ少しづつよくなればいい。作ったPGMはこのページにのせて更新していくことにする。



■プログラム配置はhttp://d.hatena.ne.jp/kazpgm/20100317/1268830031(次バージョンのプログラム配置はzendframeworkベースに+)を参照してください。

■LogininfoaController.php
view(html)http://d.hatena.ne.jp/kazpgm/20100519/1274286130 (TOOL更新_viewをphp(ver0.1)からsmarty(次期ver)へ置き換えた。)にあります。

<?php
//  =============================================================
//  2010 kaz PHP自動作成お助けTOOL.(http://kazpgm.ddo.jp/) Start
//  修正BSDライセンス。
//  =============================================================
// 管理者用Controllerの基底クラス
require_once 'ControllerAdminBase.php';
// 管理者用Logininfoテーブルユーティティ
require_once 'LogininfoaUtil.php';

// admin側Controller実装クラス
class Logininfo_LogininfoaController extends ControllerAdminBase {

    // 一番最初のソートITEM名を取得する
    protected function _getFstSrtItem() 
    {
        return 'login_type';
    }

    // 一番最初のソートタイプ(A:ASC D:DESC)を取得する
    protected function _getFstSrtType() 
    {
        return 'A';
    }

    // 検索時のチェックボックス配列対応
    protected function _cnvChkBox() 
    {
    }

    // viewに使用する名前(先頭の共通部分)
    // 例 return 'logininfoa';
    protected function _getViewHeadName() 
    {
        return 'logininfoa';
    }

    // viewに使用するフォルダ名
    // 例 return 'logininfo';
    protected function _getViewFolderName() 
    {
        return 'admin/logininfo';
    }

    // 検索条件設定
    protected function _editWhere() { // 親クラスでabstractメソッドにしてある
        $condstm = ''; // ステートメント
        $condvalary = array(); // 値の配列
        $conditions = array();
        
        // ■--PGM<<003>> start--------------------------------------------
        //  SQL条件文設定
        // 有効フラグ
        if (('' != $this->_o['srch_yuko_flg'])) {
            AppSrchUtil::setSqlStrSub1($condstm);
            $condstm .= " l.yuko_flg = ? "; // 完全一致
            $condvalary[] = $this->_o['srch_yuko_flg']; 
        }
        // ログイン権限
        if (('' != $this->_o['srch_login_type'])) {
            AppSrchUtil::setSqlStrSub1($condstm);
            $condstm .= " l.login_type = ? "; // 完全一致
            $condvalary[] = $this->_o['srch_login_type']; 
        }
        // ログインID
        if (('' != $this->_o['srch_login_id'])) {
            AppSrchUtil::setSqlStrSub1($condstm);
            $condstm .= " l.login_id = ? "; // 完全一致
            $condvalary[] = $this->_o['srch_login_id']; 
        }
        // ■--PGM<<003>> end--------------------------------------------  
        $conditions[AppConst::STM] = $condstm; // ステートメント
        $conditions[AppConst::VAL_ARY] = $condvalary; // 値の配列
        return $conditions;
    }

    // 検索条件入力値のチェック
    protected function _srchValidCheck(&$vars) { // 親クラスでabstractメソッドにしてある
        // ■--PGM<<002>> start--------------------------------------------
        $errorMessages = array();
        //  入力値チェック
        $result= true;
        // 有効フラグ
        $result= AppCheckUtil::checkCodeValue($vars, $errorMessages, "有効フラグ",  $result, "srch_yuko_flg", "YUKO_FLG", false,'0');
        // ログイン権限
        $result= AppCheckUtil::checkCodeValue($vars, $errorMessages, "ログイン権限",  $result, "srch_login_type", "LOGIN_TYPE", false,'0');
        // ログインID
        $result= AppCheckUtil::checkMoji($vars, $errorMessages, "ログインID",  $result, "srch_login_id", AppCheckUtil::CON_CHK_HALF_LETTER_DIGIT, 10, false, false,'0');
        //  検索条件入力チェック
        // if (!(AppCheckUtil::chkError($errorMessages)) && (
            // ('' == $vars['srch_yuko_flg']) && 
            // ('' == $vars['srch_login_type']) && 
            // ('' == $vars['srch_login_id']) )) {
            // 検索条件を入力してください。
            // $errorMessages['srch_topErrMessage'] = '検索条件を一つ以上入力してください。';
        // }
        // ■--PGM<<002>> end--------------------------------------------
        return $errorMessages;
    }

    // 入力値のチェック
    protected function _validCheck(&$vars, $mode) { // 親クラスでabstractメソッドにしてある
        // ■--PGM<<008>> start--------------------------------------------
        $errorMessages = array();
        //  入力値チェック
        $result= true;
        // ログインID
        if ($this->_mode == 'ins_do') {
            $result= AppCheckUtil::checkMoji($vars, $errorMessages, "ログインID",  $result, "login_id", AppCheckUtil::CON_CHK_HALF_LETTER_DIGIT, 10, false, true,'0');
        }
        // ログイン権限
        $result= AppCheckUtil::checkCodeValue($vars, $errorMessages, "ログイン権限",  $result, "login_type", "LOGIN_TYPE", true,'0');
        // パスワード
        $result= AppCheckUtil::checkMoji($vars, $errorMessages, "パスワード",  $result, "pwd1", AppCheckUtil::CON_CHK_HALF_LETTER_DIGIT, 8, false, true,'0');
        // 有効フラグ
        $result = AppCheckUtil::checkCodeValue($vars, $errorMessages, "有効フラグ",  $result, "yuko_flg", "YUKO_FLG", true,'0');
        // 登録日時
        // 更新日時
        if ($this->_mode == 'ins_do' && !AppCheckUtil::chkError($errorMessages)) { // 追加かつ、エラーなし
            $keychecks = array ();
            $keychecks['login_id'] = $vars['login_id'];
            $rtn = AppDbFunctions::logininfoGetRec($this->_db, $keychecks);
            if(!empty($rtn)) {
                $errorMessages['login_id'] = 'すでに登録されています。';
            }
        }
        // ■--PGM<<008>> end--------------------------------------------
        return $errorMessages;
    }

    // CSVダウンロード
    protected function _downLoadCsv($db, $conditions){ // 親クラスでabstractメソッドにしてある
        LogininfoaUtil::downLoadCsv($db, $conditions);
    }

    // リストの編集
    protected function _editList($db, &$o, $conditions, &$result){ // 親クラスでabstractメソッドにしてある
        LogininfoaUtil::editList($db, $o, $conditions, $result);
    }

    // 更新
    protected function _updTbl($db, &$o, &$err){ // 親クラスでabstractメソッドにしてある
        return LogininfoaUtil::updTbl($db, $o, $err);
    }

    // 詳細
    protected function _detailTbl($db, &$o){ // 親クラスでabstractメソッドにしてある
        return LogininfoaUtil::detailTbl($db, $o);
    }

    // 追加実行
    protected function _insDoTbl($db, &$o){ // 親クラスでabstractメソッドにしてある
        LogininfoaUtil::insDoTbl($db, $o);
    }

    // 更新実行
    protected function _updDoTbl($db, &$o){ // 親クラスでabstractメソッドにしてある
        return LogininfoaUtil::updDoTbl($db, $o);
    }

    // 削除実行
    protected function _delDoTbl($db, &$o){ // 親クラスでabstractメソッドにしてある
        return LogininfoaUtil::delDoTbl($db, $o);
    }

}
//  =============================================================
//  2010 kaz PHP自動作成お助けTOOL.(http://kazpgm.ddo.jp/) End
//  修正BSDライセンス。
//  =============================================================

■AppConst.php

<?php
//  =============================================================
//  2010 kaz PHP自動作成お助けTOOL.(http://kazpgm.ddo.jp/) Start
//  修正BSDライセンス。
//  =============================================================
class AppConst
{
    const STM = 'STM';         // 検索条件ステートメント
    const VAL_ARY = 'VALARY';  // 検索条件値配列
    const VAL_ADMIN = 'admin'; // 管理者側
    const VAL_USER = 'user';   // ユーザ側
    const VAL_APP = 'app';     // 当アプリケーションセッション名

}
//  =============================================================
//  2010 kaz PHP自動作成お助けTOOL.(http://kazpgm.ddo.jp/) End
//  修正BSDライセンス。
//  =============================================================

■ControllerAdminBase.php

<?php
//  =============================================================
//  2010 kaz PHP自動作成お助けTOOL.(http://kazpgm.ddo.jp/) Start
//  修正BSDライセンス。
//  =============================================================
// 管理者用Controllerの基底クラス
// kaz PHPプログラム自動作成◎自動生成お助けTOOLで作成する
// 管理者側プログラムに使用する基底クラス。
require_once 'ControllerDbBase.php';

// DBマネージャを使用する管理者側用Controller基底クラス
abstract class ControllerAdminBase extends ControllerDbBase {
    protected $_mode = '';             // モード
    protected $_modeBk = '';           // モードバックアップ
    protected $_fstSrtItem = '';       // 一番最初のソートITEM名
    protected $_fstSrtType = '';       // 一番最初のソートタイプ(A:ASC D:DESC)
    protected $_redirectUrl = null;    // リダイレクト先があるとき設定する。

    // 各アクション共通の前処理
    public function preDispatch() 
    {
        // 親クラスの各アクション共通の前処理
        parent::preDispatch();
        // ログインチェック
        if( $this->_sess['login_type'] != '1' && $this->_sess['login_type'] != '2' && $this->_sess['login_type'] != '3'){
            $this->_sess['req_url'] = $_SERVER["REQUEST_URI"];
            $this->_sessObj->array = $this->_sess;
            $this->_redirect('index');

        }
    }

    //-----------------------------------------------------------------------------------------------
    // ここからが管理者側プログラムに使用するActionメソッドです。
    // 使用例:htmlのformタグを<form name="frm" id="frm" method="post" action="以下URL参照">にする。
    //     ・新規登録しようとしたURL:/[ コントローラ名 ]/ins
    //     ・実際に新規登録したURL :/[ コントローラ名 ]/insdo
    //     ・変更登録しようとしたURL:/[ コントローラ名 ]/upd
    //     ・実際に変更規登録したURL:/[ コントローラ名 ]/upddo
    //-----------------------------------------------------------------------------------------------

    // indexアクション(実装ロジック)
    public function indexAction() 
    {
        $this->_o['mode'] = ''; // モードを空にする。
        $this->_commAct();
    }

    // 一覧アクション
    public function listAction()
    {
        $this->_o['mode'] = 'list'; // モード設定する。
        $this->_commAct();
    }

    // 検索実行アクション
    public function listdoAction()
    {
        $this->_o['mode'] = 'list_do'; // モード設定する。
        $this->_commAct();
    }

    // 一覧昇順降順アクション
    public function listupdwnAction()
    {
        $this->_o['mode'] = 'list_up_dwn'; // モード設定する。
        $this->_commAct();
    }

    // 詳細、変更から戻ったときアクション
    public function listbackAction()
    {
        $this->_o['mode'] = 'list_back'; // モード設定する。
        $this->_commAct();
    }

    // 登録アクション
    public function insAction()
    {
        $this->_o['mode'] = 'ins'; // モード設定する。
        $this->_commAct();
    }

    // 登録の実行アクション
    public function insdoAction()
    {
        $this->_o['mode'] = 'ins_do'; // モード設定する。
        $this->_commAct();
    }

    // 変更アクション
    public function updAction()
    {
        $this->_o['mode'] = 'upd'; // モード設定する。
        $this->_commAct();
    }

    // 変更の実行アクション
    public function upddoAction()
    {
        $this->_o['mode'] = 'upd_do'; // モード設定する。
        $this->_commAct();
    }

    // 削除の実行アクション
    public function deldoAction()
    {
        $this->_o['mode'] = 'del_do'; // モード設定する。
        $this->_commAct();
    }

    // 詳細の実行アクション
    public function detailAction()
    {
        $this->_o['mode'] = 'detail'; // モード設定する。
        $this->_commAct();
    }

    // CSVダウンロードの実行アクション
    public function csvAction()
    {
        $this->_o['mode'] = 'csv'; // モード設定する。
        $this->_commAct();
    }

    protected function _commActSub() { // 親クラスでabstractメソッドにしてある。親クラスの_commAct()から呼ばれる。
        $this->_o['c_elements_idx'] = '0';
        $this->_mode = strtolower($this->_o['mode']);
        $this->_modeBk = $this->_mode;
        // トークンチェックを行う。セッションは管理者側、ユーザ側別にしてあります。
        if (TokenHandle::isTokenValid($this->_getAdminKbn(), $this->_o, strtolower($this->_o['mode']), 
                             $this->_getAdminKbn() == AppConst::VAL_USER) == false) { // 管理者側トークンチェック
            // トークンチェックエラー場合
            throw new AppException('画面遷移(トークンチェック)エラーです。');
        }

        // DB begin
        $this->_dbBegin(); 

        // 一番最初のソートITEM名
        $this->_fstSrtItem = $this->_getFstSrtItem();
        $this->_fstSrtType = $this->_getFstSrtType();
        // 検索時のチェックボックス配列対応
        $this->_cnvChkBox();
        $this->_mode = strtolower($this->_o['mode']);
        switch($this->_mode) {
            case 'list':   // 一覧
            case 'list_do'://検索実行
            case 'list_up_dwn':   // 一覧昇順降順
            case 'list_back'://詳細、変更から戻ったとき
                $this->_listActionSub(); // 共通メソッド。
                break;
            case 'ins':    // 登録
            case 'ins_do': // 登録の実行
                $this->_insActionSub(); // 共通メソッド。
                break;
            case 'upd':    // 変更
            case 'upd_do': // 変更の実行
                $this->_updActionSub(); // 共通メソッド。
                break;
            case 'del_do': // 削除
                $this->_delActionSub(); // 共通メソッド。
                break;
            case 'detail': // 詳細
                $this->_detailActionSub(); // 共通メソッド。
                break;
            case 'csv'; // CSVダウンロード
                $this->_csvActionSub(); // 共通メソッド。
                break;
            default:
                $this->_listActionSub(); // 共通メソッド。
        }
        switch($this->_mode) {
            case 'ins':  // 登録
            case 'upd':  // 変更
            case 'detail':  // 詳細
            case 'list': // リスト
                break;
            default:
		        // DB commit
		        $this->_dbCommit();
                if ($this->_redirectUrl != null) {
                    $this->_redirect($this->_redirectUrl);
                }
                exit;
        }
        // HTML出力
        $this->_outHtml();
        // DB commit
        $this->_dbCommit();
    }

    // 管理者側かユーザ側かを戻す。(おもにトークンチェックで使用する)
    // "admin":管理者側、"user":ユーザ側
    protected function _getAdminKbn()
    {
         return AppConst::VAL_ADMIN; // 管理者側
    }

    // 一番最初のソートITEM名を取得する
    // 例 return 'login_type';
    abstract protected function _getFstSrtItem();

    // 一番最初のソートタイプ(A:ASC D:DESC)を取得する
    // 例 return 'A';
    abstract protected function _getFstSrtType();

    // 検索時のチェックボックス配列対応
    abstract protected function _cnvChkBox();

    // HTML出力
    protected function _outHtml() { 

        $this->_o['c_elements_idx'] = '0';
        // viewログ出力
        $this->_outViewLog($this->_o, $this->_err, $this->_result);
        $smarty  = Zend_Registry::get('smarty');
        $smarty->assign('o', $this->_o);
        $smarty->assign('err', $this->_err );
        $smarty->assign('sess', $this->_sess );
        if (isset($this->_result)) {
            $smarty->assign('result', $this->_result );
        }
        switch($this->_mode) {
        case 'ins':  // 登録
            // 登録 画面
            $smarty->display('view/' . $this->_getViewFolderName() . ($this->_getViewFolderName()==''?'':'/') . $this->_getViewHeadName() . 'RegisterView.html');
            break;
        case 'upd':  // 変更
            // 変更 画面
            $smarty->display('view/' . $this->_getViewFolderName() . ($this->_getViewFolderName()==''?'':'/') . $this->_getViewHeadName() . 'AmendView.html');
            break;
        case 'detail':  // 詳細
            // 詳細 画面
            $smarty->display('view/' . $this->_getViewFolderName() . ($this->_getViewFolderName()==''?'':'/') . $this->_getViewHeadName() . 'DetailView.html');
            break;
        case 'list': // リストs
            // リスト 画面
            $smarty->display('view/' . $this->_getViewFolderName() . ($this->_getViewFolderName()==''?'':'/') . $this->_getViewHeadName() . 'ListView.html');
            break;
        default:
            // プログラムエラー
            throw new SysException('ControllerAdminBase _outHtml: undefine mode=' . $this->_mode);
        }
    }

    // viewに使用する名前(先頭の共通部分)
    // 例 return 'logininfo';
    abstract protected function _getViewHeadName();

    // viewに使用するフォルダ名
    // 例 return 'admin/logininfo';
    abstract protected function _getViewFolderName();

    // 検索条件設定
    abstract protected function _editWhere();

    // 検索条件入力値のチェック
    abstract protected function _srchValidCheck(&$vars);

    // 入力値のチェック
    abstract protected function _validCheck(&$vars, $mode);

    // 一覧
    protected function _listActionSub() { 
        switch($this->_mode) {
            case 'list':   // 一覧
                $this->_sess['search'] = null;
                $this->_o['sort_item_name'] = $this->_fstSrtItem;
                $this->_o['sort_order'] = $this->_fstSrtType;
                $this->_sess['search'] = $this->_o;
                $this->_sessObj->array = $this->_sess;
                break;
            case 'list_do'://検索実行
                $this->_err = $this->_srchValidCheck($this->_o);
                $this->_o['sort_item_name'] = $this->_fstSrtItem;
                $this->_o['sort_order'] = $this->_fstSrtType;
                if(AppCheckUtil::chkError($this->_err)) { // エラーあり
                    $this->_sess['search'] = null;
                } else {
                    $this->_sess['search'] = $this->_o;
                }
                $this->_sessObj->array = $this->_sess;
                $this->_mode = 'list';
                break;
            case 'list_up_dwn':   // 一覧昇順降順
                $ses =& $this->_sess['search'];  // 必ずセッションに検索条件が入っている
                $ses['sort_item_name'] = $this->_o['sort_item_name'];
                $ses['sort_order'] = $this->_o['sort_order']=='A' ? 'D' : 'A'; // 空白はAにする
                $ses['pageID'] = 1; // ページは初期に戻す
                $this->_sessObj->array = $this->_sess;
                // このままlist_backのロジックを行う。
            case 'list_back'://詳細、変更から戻ったとき
                if( isset( $this->_o['pageID'] ) ){
                    $pageID = $this->_o['pageID'];
                    $this->_o = $this->_sess['search'];
                    $this->_o['pageID'] = $pageID;
                    $this->_sess['search'] = $this->_o;
                    $this->_sessObj->array = $this->_sess;
                } else {
                    if (empty($this->_sess['search'])) { // 検索条件がセッションがない場合
                        $this->_o = array();
                        $this->_o['sort_item_name'] = $this->_fstSrtItem;
                        $this->_o['sort_order'] = $this->_fstSrtType;
                        $this->_sess['search'] = $this->_o;
                        $this->_sessObj->array = $this->_sess;
                    } else {
                        $this->_o = $this->_sess['search'];
                    }
                }
                $this->_mode = 'list';
                break;
            default:
                $this->_mode = 'list';
                $this->_o['sort_item_name'] = $this->_fstSrtItem;
                $this->_o['sort_order'] = $this->_fstSrtType;
                $this->_sess['search'] = $this->_o;
                $this->_sessObj->array = $this->_sess;
        }
        $this->_o['mode']=$this->_mode;
        if (empty($this->_err)) {
            $this->_editList($this->_db, $this->_o, $this->_editWhere(), $this->_result);
        }
    }

    // 登録
    protected function _insActionSub() { 
        switch($this->_mode) {
            case 'ins':    // 登録
                break;
            case 'ins_do': // 登録の実行
                $this->_err = $this->_validCheck($this->_o, $this->_mode);
                if(AppCheckUtil::chkError($this->_err)) { // エラーあり
                    // 入力フォームを表示するmodeにする
                    $this->_mode = 'ins';
                }
                break;
        }
        $this->_o['mode']=$this->_mode;
        switch($this->_mode) {
            case 'ins':// 登録
                break;
            case 'ins_do': // 登録実行
                $this->_insDoTbl($this->_db, $this->_o);
               $this->_redirectUrl = '/'.$this->_req->getModuleName().'/'.$this->_req->getControllerName().
                                    '/ins?mode=ins';
                break;
        }
        // 登録時に、PK先取りや、パスワード先取り処理
        $this->_insActionSubSeqPass();
    }

    // 登録時に、PK先取りや、パスワード先取り処理
    // 登録時に、PK先取りや、パスワード先取りするときは、継承先でオーバーライドしてください。
    protected function _insActionSubSeqPass() 
    {
        // 登録時に、PK先取りや、パスワード先取りがあるとき処理を入れる。
    }

    // 変更
    protected function _updActionSub() { 
        switch($this->_mode) {
            case 'upd':    // 変更
                break;
            case 'upd_do': // 変更の実行
                $this->_err = $this->_validCheck($this->_o, $this->_mode);
                if(AppCheckUtil::chkError($this->_err)) { // エラーあり
                    // 入力フォームを表示するmodeにする
                    $this->_mode = 'upd';
                    // 更新エラー時に名前を戻す処理
                    $this->_updActionSubPhoto();
                }
                break;
        }
        $this->_o['mode']=$this->_mode;
        switch($this->_mode) {
            case 'upd':  // 変更
                if ($this->_err) {
                } else {
                    $delDoChkMsg = $this->_updTbl($this->_db, $this->_o, $this->_err);
                    if ('upd' == $this->_modeBk) { // リスト又は明細の更新ボタン押下
                        if ('' != $delDoChkMsg) { // レコードが削除されていたとき
                            $this->_o = $this->_sess['search'];
                            $this->_o['del_do_chk_msg'] = $delDoChkMsg;
                            $this->_o =& $this->_o; // output用(FORMからの入力値)
                            $this->_mode = 'list';
                            $this->_editList($this->_db, $this->_o, $this->_editWhere(), $this->_result);
                        }
                    }
                }
                break;
            case 'upd_do':
                $delDoChkMsg = $this->_updDoTbl($this->_db, $this->_o);
                if ('' == $delDoChkMsg) { // 更新できたとき
                   $this->_redirectUrl = '/'.$this->_req->getModuleName().'/'.$this->_req->getControllerName().
                                        '/listback?mode=list_back';
                } else {
                    $this->_o = $this->_sess['search'];
                    $this->_o['del_do_chk_msg'] = $delDoChkMsg;
                    $this->_o =& $this->_o; // output用(FORMからの入力値)
                    $this->_mode = 'list';
                    $this->_editList($this->_db, $this->_o, $this->_editWhere(), $this->_result);
                }
                break;
        }
    }

    // 更新エラー時に名前を戻す処理
    // アップロード処理のとき、継承先でオーバーライドしてください。
    protected function _updActionSubPhoto() 
    {
        // アップロードがあるとき処理を入れる。
    }

    // 削除
    protected function _delActionSub() { 
        $this->_o['mode']=$this->_mode;
        $delDoChkMsg = $this->_delDoTbl($this->_db, $this->_o);
        if ('' == $delDoChkMsg) { // 削除できたとき
           $this->_redirectUrl = '/'.$this->_req->getModuleName().'/'.$this->_req->getControllerName().
                                '/listback?mode=list_back';
        } else {
            $this->_o = $this->_sess['search'];
            $this->_o['del_do_chk_msg'] = $delDoChkMsg;
            $this->_o =& $this->_o; // output用(FORMからの入力値)
            $this->_mode = 'list';
            $this->_editList($this->_db, $this->_o, $this->_editWhere(), $this->_result);
        }
    }

    // 詳細
    protected function _detailActionSub() { 
        $this->_o['mode']=$this->_mode;
        $delDoChkMsg = $this->_detailTbl($this->_db, $this->_o);
        if ('' != $delDoChkMsg) { // レコードが削除されていたとき
            $this->_o = $this->_sess['search'];
            $this->_o['del_do_chk_msg'] = $delDoChkMsg;
            $this->_o =& $this->_o; // output用(FORMからの入力値)
            $this->_mode = 'list';
            $this->_editList($this->_db, $this->_o, $this->_editWhere(), $this->_result);
        }
    }

    // CSVダウンロード
    protected function _csvActionSub() { 
        $conditions = '';
        $this->_o = $this->_sess['search'];
        $conditions = $this->_editWhere();
        $this->_downLoadCsv($this->_db, $conditions);
    }

    // CSVダウンロード
    abstract protected function _downLoadCsv($db, $conditions);

    // リストの編集
    abstract protected function _editList($db, &$o, $conditions, &$result);

    // 更新
    abstract protected function _updTbl($db, &$o, &$err);

    // 詳細
    abstract protected function _detailTbl($db, &$o);

    // 追加実行
    abstract protected function _insDoTbl($db, &$o);

    // 更新実行
    abstract protected function _updDoTbl($db, &$o);

    // 削除実行
    abstract protected function _delDoTbl($db, &$o);


}
//  =============================================================
//  2010 kaz PHP自動作成お助けTOOL.(http://kazpgm.ddo.jp/) End
//  修正BSDライセンス。
//  =============================================================

■ControllerDbBase.php

<?php
//  =============================================================
//  2010 kaz PHP自動作成お助けTOOL.(http://kazpgm.ddo.jp/) Start
//  修正BSDライセンス。
//  =============================================================
// DBマネージャを使用するプログラム用Controller基底クラス。
require_once 'ControllerBase.php';
require_once('TokenHandle.php');
require_once('DbManager.php');
require_once('DbManagerForSeq.php');
require_once('AppDbFunctions.php');

// DBマネージャを使用するプログラムに使用する。
abstract class ControllerDbBase extends ControllerBase {
    protected $_db = null;             // DBマネージャ
    protected $_result = array();      // DBクエリ結果

    // 前処理
    protected function _preDo() 
    {
        $DSN_ZEND  = Zend_Registry::get('DSN_ZEND');
        $this->_db = DbManager::getInstance($DSN_ZEND, 'uid'); // DB接続
        parent::_preDo();

    }

    // DB begin。
    protected function _dbBegin()
    {
        if ($this->_db != null) {
            $this->_db->beginTransaction();
        }
    }

    // DB commit。。
    protected function _dbCommit()
    {
        if ($this->_db != null) {
           $this->_db->commit();
        }
    }

    // DB rollback。
    protected function _dbRollback()
    {
        if ($this->_db != null) {
            $this->_db->rollback();
        }
    }

}
//  =============================================================
//  2010 kaz PHP自動作成お助けTOOL.(http://kazpgm.ddo.jp/) End
//  修正BSDライセンス。
//  =============================================================

■ControllerBase.php

<?php
//  =============================================================
//  2010 kaz PHP自動作成お助けTOOL.(http://kazpgm.ddo.jp/) Start
//  修正BSDライセンス。
//  =============================================================
require_once 'Zend/Controller/Action.php';
require_once 'Zend/Log.php';
require_once 'Zend/Log/Writer/Stream.php';
require_once('AppHtmlUtil.php');
require_once('AppElements.php');
require_once('AppLogr.php');
require_once('AppConst.php');

// DBマネージャを使わないもの用Controller基底クラス。
abstract class ControllerBase extends Zend_Controller_Action {

    protected $_err = array();         // エラー
    protected $_o = array();           // 画面入力データ(array)
    protected $_sess = array();        // セッションデータ(array)
    protected $_sessObj = null;        // app用セッション
    protected $_req = null;            // リクエスト(getRequest())
    protected $_logger = null;         // ログ出力オブジェクト

    // 各アクション共通の前処理
    public function preDispatch() 
    {
        $this->_preDo();  
    }

    // 前処理
    protected function _preDo() 
    {
        // ログ
        $this->_logger = new AppLogr($this->_getDebugDir(), $this->_getDebugFlg());
        $this->_err = array(); // エラーメッセージがある場合は入れる
        $this->_sessObj = new Zend_Session_Namespace(AppConst::VAL_APP);    // app用セッション
        $this->_sess = $this->_sessObj->array;    // セッションデータ(array)
        $this->_req = $this->getRequest();        // リクエスト(getRequest())
        $this->_o = $this->_req->getParams();    // 画面入力データ(array)
        // 入力データダンプ
        if ($this->_getStartDebugFlg() == true) {
            $this->_logger->outDbgLog('[START]: _sess', $this->_sess);    // セッションデータ(array)
            $this->_logger->outDbgLog('[START]: _o', $this->_o);    // 画面入力データ(array)
        }
    }

    // indexアクション(実装ロジック)
    public function indexAction() 
    {
        $this->_commAct();
    }

    // 共通アクション(実装ロジック)
    public function _commAct() 
    {
        try {
            $this->_commActSub();
        // プログラム内のアプリケーション用例外
        } catch (AppException $e) {
            // エラー画面出力
            $this->_outErrHtml($e, Zend_Log::WARN);
            // DB rollback(継承先でDB使わないときは何もしない)
            $this->_dbRollback();
            exit;
        // プログラム内のシステム用例外
        } catch (SysException $e) {
            if ($this->_logger != null) {
                $this->_logger->outErrLog('The Sys Error occurred. ' . $e->getFile().":". 
                                                $e->getLine().":". $e->getMessage(), Zend_Log::ERR);
                echo 'Sys : Message: ' . 'The Sys Error occurred. ' . "<br />\n";
            } else {
                echo 'Sys : Message: ' . 'The Sys Error occurred. And logger = null.' . "<br />\n";
            }
            // DB rollback(継承先でDB使わないときは何もしない)
            $this->_dbRollback();
            exit;
        // プログラム内のシステム用例外
        } catch (OtherException $e) {
            if ($this->_logger != null) {
                $this->_logger->outErrLog('The Other Error occurred. ' . $e->getFile().":". 
                                                $e->getLine().":".$e->getMessage(), Zend_Log::ERR);
                echo 'Sys : Message: ' . 'The Other Error occurred. ' . "<br />\n";
            } else {
                echo 'Sys : Message: ' . 'The Other Error occurred. And logger = null.' . "<br />\n";
            }
            // DB rollback(継承先でDB使わないときは何もしない)
            $this->_dbRollback();
            exit;
        // ZENDなどが出す例外
        } catch (Exception $e) {
            if ($this->_logger != null) {
                $this->_logger->outErrLog('The Error occurred. ' . $e->getFile().":". 
                                            $e->getLine().":".$e->getMessage(), Zend_Log::ERR);
                echo ' Message: ' . 'The Error occurred. ' . "<br />\n";
            } else {
                echo ' Message: ' . 'The Error occurred. And logger = null.' . "<br />\n";
            }
            // DB rollback(継承先でDB使わないときは何もしない)
            $this->_dbRollback();
            exit;
        }
    }

    // 共通アクション
    abstract protected function _commActSub();

    // 業務例外画面出力(管理者側ユーザ側共通)
    protected function _outErrHtml($e, $priority) 
    {
        if ($this->_logger != null) {
            $this->_logger->outErrLog($e->getFile().":". $e->getLine().":".
                                                    $e->getMessage(), $priority);
        }
        $this->_err['exception_msg'] = $e->getMessage();
        // エラー 画面
        $smarty  = Zend_Registry::get('smarty');
        $smarty->assign('o', $this->_o);
        $smarty->assign('err', $this->_err );
        $adminUserId  = Zend_Registry::get('adminUserId');
        if ($adminUserId == AppConst::VAL_ADMIN) {
            $smarty->display(ADMIN_ERR_HTML);
        } else {
            $smarty->display(USER_ERR_HTML);
        }
    }

    // DB rollback:継承先でDBを使う場合、rollbackを行う。
    // (継承先でDB使わないときは何もしない)
    protected function _dbRollback()
    {
    }

    // 未定義のメソッドを実行
    public function __call($method, $args)
    {
        if ('Action' == substr($method, -6)) {
            // アクションメソッドが見つからなかった場合は、index アクションに転送します
            return $this->_forward('index');
        }
        // その他のメソッドの場合は例外をスローします。
        throw new SysException('Invalid method "' . $method . '" called');
    }

    // デバック出力先を戻す
    protected function _getDebugDir() {
        return DIR_LOG;
    }

    // デバック出力設定を戻す
    protected function _getDebugFlg() {
        return DEBUG_FLG;
    }

    // 入力デバックフラグを戻す
    protected function _getStartDebugFlg() {
        return START_DEBUG_FLG;
    }

    // 出力デバックフラグを戻す
    protected function _getEndDebugFlg() {
        return END_DEBUG_FLG;
    }

    // viewログ出力
    //「_outHtml」メソッドを実装するとき当メソッドを呼んでください。
    protected function _outViewLog(&$o, &$err, &$result) {
        if (END_DEBUG_FLG == true) {
            // セッションデータダンプ
            if (!empty($this->_sess)) {
                $this->_logger->outDbgLog('[END]: _sess', $this->_sess);    // セッションデータ(array)
            }
            // view出力値ダンプ
            if (!empty($o)) {
                $this->_logger->outDbgLog('[END] o', $o);    //view oデータ(array)
            }
            if (!empty($err)) {
                $this->_logger->outDbgLog('[END] err', $err);    //view errデータ(array)
            }
            if (!empty($result)) {
                $this->_logger->outDbgLog('[END] result', $result);    //view resultデータ(array)
            }
            $this->_logger->outDbgLog('[END] ///--------');    //viewデータ(array)
        }
    }

}
//  =============================================================
//  2010 kaz PHP自動作成お助けTOOL.(http://kazpgm.ddo.jp/) End
//  修正BSDライセンス。
//  =============================================================

■AppDbInterface.php

<?php
interface AppDbInterface
{
    // CSVダウンロード
    public function downLoadCsv($db, $conditions);
    // リストの編集
    public function editList($db, &$o, $conditions, &$result);
    // 更新
    public function updTbl($db, &$o, &$err);
    // 詳細
    public function detailTbl($db, &$o);
    // 追加実行
    public function insDoTbl($db, &$o);
    // 更新実行
    public function updDoTbl($db, &$o);
    // 削除実行
    public function delDoTbl($db, &$o);
}

■LogininfoaUtil.php

<?php
require_once('AppDbInterface.php');
require_once('AppLogr.php');

class LogininfoaUtil implements AppDbInterface 
{
    // CSVダウンロード
    public function downLoadCsv($db, $conditions) {
        $elements = AppElements::getInstance();
        $ELEMENTS = &$elements->elements;    // コード一覧
        $condstm = $conditions[AppConst::STM];    // ステートメント
        $valary = $conditions[AppConst::VAL_ARY]; // 値の配列

        if ('' != $condstm) {
            $condstm = "WHERE ". $condstm;
        }
$sql = <<<__SQL__
SELECT 
        -- ■--PGM<<009>> start--------------------------------------------
            l.login_id, --  ログインID
            l.login_type, --  ログイン権限
            l.pwd1, --  パスワード
            l.yuko_flg --  有効フラグ
        -- ■--PGM<<009>> end--------------------------------------------
FROM m_logininfo l
$condstm 
ORDER BY 
        -- ■--PGM<<009>> start--------------------------------------------
            l.login_id, --  ログインID
            l.login_type, --  ログイン権限
            l.pwd1 --  パスワード
        -- ■--PGM<<009>> end--------------------------------------------
__SQL__;
        $result = $db->getAll($sql, $valary);
        $csvStr = '';
        header("Content-Disposition: attachment; filename=logininfoaList.csv");
        header("Content-Type: application/octet-stream");
        header("Cache-Control: public");
        header("Pragma: public");
        $csvStr .= "ログインID, ログイン権限,ログイン権限(名称), パスワード, 有効フラグ,有効フラグ(名称)\n";
        foreach( $result as $vals ){
            $csvItemCount = 0;
            $valsNew = array();
            foreach( $vals as $key => $val ){
                $valsNew[$key] = $val;
                $csvItemCount++;
                if ($csvItemCount == 2) { // ログイン権限
                    $valsNew[$key . '_value'] = $ELEMENTS['LOGIN_TYPE'][$val]['0'];
                }
                if ($csvItemCount == 4) { // 有効フラグ
                    $valsNew[$key . '_value'] = $ELEMENTS['YUKO_FLG'][$val]['0'];
                }
            }
            $vals = $valsNew;
            foreach( $vals as $key => $val ){
                $vals[$key] = eregi_replace( "\"" , "\"\"", $val );
            }
            $csvStr .=  "\"" . implode( "\",\"", $vals ) . "\"\n";
        }
        $csvLen = strlen( $csvStr );
        header('Content-Length: ' .  $csvLen);
        mb_convert_variables('SJIS-win', 'UTF-8', $csvStr);
        print $csvStr;
    }


    // リストの編集
    public function editList($db, &$o, $conditions, &$result) {
        $limit = 10; // 表示件数
        $offset = ( intval($o['pageID']) -1) * $limit ;
        $offset = $offset < 0 ? 0 : $offset;
        $condstm = $conditions[AppConst::STM];        // ステートメント
        $valary = $conditions[AppConst::VAL_ARY]; // 値の配列

        if ('' != $condstm) {
            $condstm = "WHERE ". $condstm;
        }
        $listOrder = ' ' . editDbItemName($o['sort_item_name']) . ' ' . ($o['sort_order']=='A' ? 'ASC' : 'DESC');
$sql = <<<__SQL__
SELECT 
        -- ■--PGM<<004>> start--------------------------------------------
            l.login_id, --  ログインID
            l.login_type, --  ログイン権限
            l.pwd1, --  パスワード
            l.yuko_flg --  有効フラグ
        -- ■--PGM<<004>> end--------------------------------------------
FROM m_logininfo l 
 $condstm 
ORDER BY  $listOrder 
LIMIT $offset, $limit
__SQL__;
        $result = $db->getAll($sql, $valary);
// 全件数
$sql = <<<__SQL__
SELECT count(*) 
FROM m_logininfo l
 $condstm
__SQL__;
        $count = $db->getOne( $sql, $valary);
        $pageNavi =& new PageNavi(array(
            'totalItems' => $count,
            'perPage'    => $limit,
            //'prevPageNaviText'  => '',
            //'prevPageNaviSpace' => '',
            //'firstPageSpace'    => '',
            //'prevImg'           => '前へ',
            //'nextImg'           => '次へ',
            //'lastPageSpace'     => '',
            //'nextPageNaviSpace' => '',
            //'nextPageNaviText'  => '',
            //'firstPageTextFlag' => '0',
            //'lastPageTextFlag'  => '0',
            'extraVars' => array()
        ),'0');
        $pager = $pageNavi->getHTML();
        $o['pager'] = $pager;
    }

    // 更新
    public function updTbl($db, &$o, &$err) {
        $valary = array(); // 値の配列
        if(!$err) {
            $valary[] = $o['login_id'];
$sql = <<<__SQL__
SELECT 
        -- ■--PGM<<005>> start--------------------------------------------
            l.*, date_format(l.logininfo_insert, '%Y/%m/%d %H:%i:%s') AS logininfo_insert, --  登録日時
            date_format(l.logininfo_insert, '%Y') AS logininfo_insert_year ,
            date_format(l.logininfo_insert, '%m') AS logininfo_insert_month ,
            date_format(l.logininfo_insert, '%d') AS logininfo_insert_day ,
            date_format(l.logininfo_update, '%Y/%m/%d %H:%i:%s') AS logininfo_update, --  更新日時
            date_format(l.logininfo_update, '%Y') AS logininfo_update_year ,
            date_format(l.logininfo_update, '%m') AS logininfo_update_month ,
            date_format(l.logininfo_update, '%d') AS logininfo_update_day 
        -- ■--PGM<<005>> end--------------------------------------------
FROM m_logininfo l 
WHERE login_id = ?
__SQL__;
            $msg = '指定されたログイン情報は削除されています。' . ' ログインID=' . $o['login_id'] ; // 削除されている
            $o = $db->getRow($sql, $valary);
            if (empty($o)) {
                return $msg; // 削除されている
            }
        }
    }

    // 詳細
    public function detailTbl($db, &$o) {
        $valary = array(); // 値の配列
        $valary[] = $o['login_id'];
$sql = <<<__SQL__
SELECT 
        -- ■--PGM<<005>> start--------------------------------------------
            l.*, date_format(l.logininfo_insert, '%Y/%m/%d %H:%i:%s') AS logininfo_insert, --  登録日時
            date_format(l.logininfo_insert, '%Y') AS logininfo_insert_year ,
            date_format(l.logininfo_insert, '%m') AS logininfo_insert_month ,
            date_format(l.logininfo_insert, '%d') AS logininfo_insert_day ,
            date_format(l.logininfo_update, '%Y/%m/%d %H:%i:%s') AS logininfo_update, --  更新日時
            date_format(l.logininfo_update, '%Y') AS logininfo_update_year ,
            date_format(l.logininfo_update, '%m') AS logininfo_update_month ,
            date_format(l.logininfo_update, '%d') AS logininfo_update_day 
        -- ■--PGM<<005>> end--------------------------------------------
FROM m_logininfo l 
WHERE login_id = ?
__SQL__;
        $msg = '指定されたログイン情報は削除されています。' . ' ログインID=' . $o['login_id'] ; // 削除されている
        $o = $db->getRow($sql, $valary);
        if (empty($o)) {
            return $msg; // 削除されている
        }
    }

    // 追加実行
    public function insDoTbl($db, &$o) {
            // ■--PGM<<010>> start--------------------------------------------
            // ■--PGM<<010>> end--------------------------------------------
        $sql = 'INSERT INTO ' . 'm_logininfo' . ' ( '.
            // ■--PGM<<010>> start--------------------------------------------
            'login_id, ' . // ログインID
            'login_type, ' . // ログイン権限
            'pwd1, ' . // パスワード
            'yuko_flg, ' . // 有効フラグ
            'logininfo_insert, ' . // 登録日時
            'logininfo_update ' .  // 更新日時
            ' ) VALUES (?,?,?,?,?,?)'; 
            // ■--PGM<<010>> end--------------------------------------------
        $valary = array();
        $valary[] = $o['login_id']; // ログインID
        $valary[] = $o['login_type']; // ログイン権限
        $valary[] = $o['pwd1']; // パスワード
        $valary[] = $o['yuko_flg']; // 有効フラグ
        $valary[] = date( 'Y/m/d H:i:s' ); // 登録日時
        $valary[] = date( 'Y/m/d H:i:s' ); // 更新日時
        
        $db->query($sql, $valary);
    }

    // 更新実行
    public function updDoTbl($db, &$o) {
            // ■--PGM<<010>> start--------------------------------------------
            // ■--PGM<<010>> end--------------------------------------------

        $sql = 'UPDATE ' . 'm_logininfo' . ' SET '.
            // ■--PGM<<010>> start--------------------------------------------
            'login_type = ?, ' . // ログイン権限
            'pwd1 = ?, ' . // パスワード
            'yuko_flg = ?, ' . // 有効フラグ
            'logininfo_update = ? ' . // 更新日時
            ' WHERE ' .
            'login_id = ? '; // ログインID
            // ■--PGM<<010>> end--------------------------------------------
        $valary = array();
        $valary = array();
        $valary[] = $o['login_type']; // ログイン権限
        $valary[] = $o['pwd1']; // パスワード
        $valary[] = $o['yuko_flg']; // 有効フラグ
        $valary[] = date( 'Y/m/d H:i:s' ); // 更新日時
        $valary[] = $o['login_id']; // ログインID

        $db->query($sql, $valary);
    }

    // 削除実行
    public function delDoTbl($db, &$o) {
        $sql = 'DELETE FROM ' . 'm_logininfo' . 
            ' WHERE ' . // 更新日時
            'login_id = ? ';
        $valary = array();
        $valary[] = $o['login_id']; // ログインID

        $rtn = $db->query($sql, $valary)->rowCount();
        if (1 > $rtn) { // 更新なしの場合

            return '指定されたログイン情報は削除されています。' . ' ログインID=' . $o['login_id'] ; // 削除されている
        }
    }
}

http://kazpgm.ddo.jp/

01/21 22:00-01:00 01:30-03:00
02/11 15:30-16:00
・02/11 LogininfoaController.php、ControllerABase.php、ControllerABaseExt.php、Interface.php、LogininfoaUtil.phpを載せた。DBはまだZend_DBにしていない。徐々にする予定。

03/09 01:00-01:30 DBをZend_DBを使ったDbManagerクラスにした
03/11 01:00-01:30 LogininfoaUtil.php DBマネージャクラスのdbDeleteメソッドから更新件数を返すように修正。直接修正。コメントなし。
03/15 23:30-23:30 Admin_LogininfoaController.php 「$this->_db->quoteSmart」を「$this->_db->dbQuote」に変更した。 
03/15 0:30:0:30 「ControllerABase.php」に「require_once('AppDbFunctions.php');」を追加した。
04/14 2:00-2:00 「ControllerABase.php」を「indexAction()、_outErrHtml($e, $priority)、_indexActionSub()、__call($method, $args)、_preDo() 」メソッドだけにして、それ以外のメソッドは「ControllerABaseExt.php」に移動した。http://d.hatena.ne.jp/kazpgm/20100121/1264095498を直接修正した。
04/20 23:30-00:00 「ControllerABase」は「ControllerBase」を作ってこちらを継承した。
04/28 01:40-01:50 「ControllerABase.php」にモード別にアクションメソッドを追加した。
6/9 01:30-2:30 viewをsmartyにしたり。DBマネージャを修正したり。などのため差し替え、プログラムは直接書き換えた。
7/3 08:00-18:00
7/7 06:00-08:00 全面修正。http://d.hatena.ne.jp/kazpgm/20100707/1278456337 (TOOL更新_ベースになるサンプルを作成中。の続き。)参照
7/7 21:30-22:00 ■プログラム配置の画像を削除して、自日記内へのリンクにした。
7/19 11:30-11:30 http://d.hatena.ne.jp/kazpgm/20100719/1279504742(TOOL更新_管理者側ログインチェックを作った。Ver0.1と同じものをZend frameworksmartyにした。さらに、いろいろ修正。)参照
8/9 10:30-11:00 http://d.hatena.ne.jp/kazpgm/20100809/1281315402の内容を反映した。
8/14 9:30-9:40 AppConst.phpを追記した。 16:30-16:40 LogininfoaController.phpの_validCheck、_srchValidCheckメソッド中の「$this->result」を「$result」に変更した。
(「$this->result」はDB取得結果を入れとくものなので。)
8/14 1:00-1:30 ControllerAdminBase.phpに以下を追加した。ソート”▲”と"▼"がうまく出なかったのを修正した。

        $this->_fstSrtType = $this->_getFstSrtType();

8/25 3:10-3:10 「AppConst.php、ControllerBase.php」にhttp://d.hatena.ne.jp/kazpgm/20100825/1282758753(TOOL更新_ユーザ側作成に伴って作成済みPGMを微調整)を反映した。
9/23 17:00-17:30

if (TokenHandle::isTokenValid($this->_getAdminKbn(), strtolower($this->_o['mode']), 
$this->_getAdminKbn() == AppConst::VAL_USER) == false) { // 管理者側トークンチェック
を
if (TokenHandle::isTokenValid($this->_getAdminKbn(), $this->_o, strtolower($this->_o['mode']), 
$this->_getAdminKbn() == AppConst::VAL_USER) == false) { // 管理者側トークンチェック
に変更した

10/4 21:00-22:30 ユーザ用エラー画面の指定が違っていたので修正した。

■ControllerBase.php
protected function _outErrHtml($e, $priority) 
        if ($adminUserId == AppConst::VAL_ADMIN) {
            $smarty->display(ADMIN_ERR_HTML);
        } else {
<<修正前>>
            $smarty->display(ADMIN_ERR_HTML);
<<修正後>>
            $smarty->display(USER_ERR_HTML);

2011/02/01 23:00-23:10 LogininfoAをLogininfoa、logininfoAをlogininfoaに修正した。これはhttp://d.hatena.ne.jp/kazpgm/20110131/1296487044による修正を反映したもの。
2011/03/07 4:00-4:10 http://d.hatena.ne.jp/kazpgm/20110307/1299523681(TOOL更新_Ver0.1Zd(次期バージョン)の管理者側もすべてアクションで切り分けるように修正した。(modeパラメータを使わないようにした。)など。)の内容を反映した。