1 2 3 4 5 6 7 8 9 10 11 12 | //---------------------------------------------------------------- //サブミットボタン調査 //---------------------------------------------------------------- function _getSubmitButtonName( $array ) { $target = $this ->params[ 'form' ]; foreach ( $array as $i ) { if ( array_key_exists ( $i , $target )) return $i ; if ( array_key_exists ( $i . '_x' , $target ) && array_key_exists ( $i . '_y' , $target )) return $i ; } return null; } |
1 2 | <?php echo $this ->Form->submit( 'button_image.jpg' , array ( 'name' => 'do_regist' )); ?> <?php echo $this ->Form->submit( 'button_image.jpg' , array ( 'name' => 'do_edit' )); ?> |
コントローラーで次のように_getSubmitButtonName()を呼ぶ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | if (! empty ( $this ->data)){ //登録処理 // $buttonName = $this ->_getSubmitButtonName( array ( 'do_regist' , 'do_edit' )); if ( $buttonName === 'do_regist' ) { //保存の実行 // //確認処理 // } else if ( $buttonName !== 'do_edit' ) { //値のチェック // if ( $flag ){ $this ->render( 'edit_confirm' ); //確認のviewを表示 } } } |
返値をnameでチェックして処理を分ければよい。
0 件のコメント:
コメントを投稿