powered by nequal

rhaco1-doc :: 002-model/03-hook-method.txt

http://wikihub.org/wiki/rhaco1-doc/002-model/03-hook-method

Table of contents:

collapse all expand all

Updates:

フックメソッド

project.xml から生成した Model に対して, DbUtil を用いて操作を行った際にその動作をフックメソッドを用いて制御することが可能です.

beforeInsert

INSERT前に呼ばれます.

<?php
Rhaco::import("model.table.ProfileTable");
/**
 * プロフィール
 */
class Profile extends ProfileTable{
	/**
	 * INSERT 前処理
	 * @param DbUtil $db
	 */
    function beforeInsert($db){
    	return true;
    }
}

afterInsert

データベースにINSERTした後に呼ばれます.

<?php
Rhaco::import("model.table.ProfileTable");
/**
 * プロフィール
 */
class Profile extends ProfileTable{
	/**
	 * INSERT 後処理
	 * @param DbUtil $db
	 */
    function afterInsert($db){
    	return true;
    }
}

beforeUpdate

UPDATE 前に呼ばれます.

<?php
Rhaco::import("model.table.ProfileTable");
/**
 * プロフィール
 */
class Profile extends ProfileTable{
	/**
	 * UPDATE 前処理
	 * @param DbUtil $db
	 */
    function beforeUpdate($db){
    	return true;
    }
}

afterUpdate

UPDATE 後に呼ばれます.

<?php
Rhaco::import("model.table.ProfileTable");
/**
 * プロフィール
 */
class Profile extends ProfileTable{
	/**
	 * UPDATE 後処理
	 * @param DbUtil $db
	 */
    function afterUpdate($db){
    	return true;
    }
}

beforeDelete

DELETE 前に呼ばれます.

Model には標準で beforeDelete メソッドが実装されていますので,オーバーライドした際には,呼ぶ必要があります.

<?php
Rhaco::import("model.table.ProfileTable");
/**
 * プロフィール
 */
class Profile extends ProfileTable{
	/**
	 * DELETE 前処理
	 * @param DbUtil $db
	 */
    function beforeDelete($db){
    	if(parent::beforeDelete($db)){
    		return false;
    	}
    	return false;
    }
}

afterUpdate

DELETE 後に呼ばれます.

<?php
Rhaco::import("model.table.ProfileTable");
/**
 * プロフィール
 */
class Profile extends ProfileTable{
	/**
	 * Delete 後処理
	 * @param DbUtil $db
	 */
    function afterDelete($db){
    	return true;
    }
}

afterGet

DbUtil::get 後に呼ばれます.

<?php
Rhaco::import("model.table.ProfileTable");
/**
 * プロフィール
 */
class Profile extends ProfileTable{
	/**
	 * Get 後処理
	 * @param DbUtil $db
	 */
    function afterGet($db){
 
    }
}

afterSelect

DbUtil::select 後に呼ばれます.

<?php
Rhaco::import("model.table.ProfileTable");
/**
 * プロフィール
 */
class Profile extends ProfileTable{
	/**
	 * Get 後処理
	 * @param DbUtil $db
	 */
    function afterSelect($db){
 
    }
}