2012年7月18日水曜日

qdmail 何度も使う場合は

qdmail を何度も使う場合は$this->Qdmail->reset();を実行して内部変数を初期化する

2012年7月17日火曜日

[cakephp 1.3] 複数あるサブミットボタンのどれが押されたか調査する。

コントローラーに以下のファンクションを追加する。
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でチェックして処理を分ければよい。

2012年7月9日月曜日

[cakephp] Formヘルパー


$this->Form->chckbox()のオプション

echo $this->Form->checkbox('hoge',array('label'=>'hoge'));
と書いた時以下のように出力される。





この時チェックされなかった時に値が"0"となるようにする仕掛けhiddenが要らない時

optionsに'hiddenField'=>false入れておくとこれが表示されない。