2017 © Pedro Peláez
 

cakephp-plugin post-transition

CakePHP PostTransition

image

satthi/post-transition

CakePHP PostTransition

  • Monday, May 16, 2016
  • by satthi
  • Repository
  • 1 Watchers
  • 0 Stars
  • 278 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 3 % Grown

The README.md

PostTransition

PostTransition for Cakephp3, (*1)

複数ページ遷移を簡単にpostで管理するプラグインです。, (*2)

次ページ等の移動はpostで行うため複数タブにも対応が可能です。, (*3)

また、画面の順番の概念を持たないのでどこの画面に遷移をすることも可能です。, (*4)

(たとえば確認画面から途中の画面に戻って修正して再度確認画面に戻るなど), (*5)

使い方

setやgetを使用していない場合はこちらでOK

TopicsController.php, (*6)

 'next',
            //前へボタンのprefix(default はback)
            //'backPrefix' => 'back',
            //現在の状態をセッションで管理するキー(defaultはnow)
            //'nowField' => 'now',
            //扱うモデル
            'model' => 'Topics',
            //初期遷移時の設定
            'default' => [
                //初期値
                //'value' => [],
                //初期画面の設定はpost配列内のどの設定か
                'post_setting' => 'index1',
            ],
            //privateの第二引数に特定の値を引き渡す
            'param' => [],
            //post時の設定
            'post' => [
                //key値は、ボタン名や独自メソッドへのアクセスに使用
                'index1' => [
                    //使用するview
                    'render' => 'index1',
                    //バリデーションをかける際のentity作成第二引数の設定
                    'validate_option' => ['validate' => 'index1']
                ],
                'index2' => [
                    'render' => 'index2',
                    'validate_option' => ['validate' => 'index2']
                ],
                'index3' => [
                    'render' => 'index3',
                    'validate_option' => ['validate' => 'index3']
                ],
                'save' => [
                    'render' => false,
                    'validate_option' => ['validate' => false]
                ],
            ],
        ];
        $this->__postTransition($settings);
    }
    
    //index1の画面描画前(entityセット直前でフック)
    private function __index1($entity, $param){
       $entity->hoge4 = 'are';
    }
    
    //save処理
    private function __save($entity, $param){
        debug($entity);
        //save 処理
    }
}
```

index1.ctp

```
index1
hoge4:= $entity->hoge4;?><br /> = $this->Form->create($entity);?> = $this->Form->input('hoge1',['required' => false]);?> = $this->Form->input('hidden_key');?> = $this->Form->input('now');?> = $this->Form->submit('submit', ['name' => 'next_index2']);?> = $this->Form->end();?>

index2.ctp, (*7)

index2<br />
hoge1:= $entity->hoge1;?>

= $this->Form->create($entity);?>

= $this->Form->input('hoge2',['required' => false]);?>
= $this->Form->input('hidden_key');?>
= $this->Form->input('now');?>


= $this->Form->submit('back', ['name' => 'back_index1']);?>

= $this->Form->submit('next', ['name' => 'next_index3']);?>
= $this->Form->end();?>

index3.ctp, (*8)

index3<br />
hoge1:= $entity->hoge1;?><br />
hoge2:= $entity->hoge2;?><br />
= $this->Form->create($entity);?>

= $this->Form->input('hoge3',['required' => false]);?>
= $this->Form->input('hidden_key');?>
= $this->Form->input('now');?>


= $this->Form->submit('back1', ['name' => 'back_index1']);?>

= $this->Form->submit('back2', ['name' => 'back_index2']);?>

= $this->Form->submit('next', ['name' => 'next_save']);?>
= $this->Form->end();?>

パスワードなどsetやgetでフォームの項目で使用している場合はこちらを参考に

TopicsController.php, (*9)

loadComponent('RequestHandler');
    }

    public function add()
    {
        $topicForm = new TopicForm();
        $settings = [
            //次へボタンのprefix(default はnext)
            //'nextPrefix' => 'next',
            //前へボタンのprefix(default はback)
            //'backPrefix' => 'back',
            //現在の状態をセッションで管理するキー(defaultはnow)
            //'nowField' => 'now',
            //扱うモデル
            'model' => $topicForm,
            //初期遷移時の設定
            'default' => [
                //初期値
                'value' => [
                    // 'hoge1' => 'hoge'
                ],
                //初期画面の設定はpost配列内のどの設定か
                'post_setting' => 'index1',
            ],
            'param' => 'hogehoge',
            //post時の設定
            'post' => [
                //key値は、ボタン名や独自メソッドへのアクセスに使用
                'index1' => [
                    //使用するview
                    'render' => 'index1',
                    //バリデーションをかける際のentity作成第二引数の設定
                    'validate_option' => ['validate' => 'index1']
                ],
                'index2' => [
                    'render' => 'index2',
                    'validate_option' => ['validate' => 'index2']
                ],
                'index3' => [
                    'render' => 'index3',
                    'validate_option' => ['validate' => 'index3']
                ],
                'save' => [
                    'render' => false,
                    'validate_option' => ['validate' => false]
                ],
            ],
        ];
        $this->__postTransition($settings);
    }

    //index1の画面描画前(entityセット直前でフック)
    private function __index1($data, $param){
        var_dump($data);
        var_dump($param);
    }

    //save処理
    private function __save($data, $param){
        $this->Topics = TableRegistry::get('Topics');
        debug($this->Topics->newEntity($data));
        //save 処理
    }
}

```

TopicForm.php  
(バリデーションの処理をTableではなくForm側に持たせる)
```
notEmpty('hoge1', 'required singer_id');
        return $validator;
    }

    public function validationIndex1(Validator $validator)
    {
        $validator
            ->notEmpty('hoge1', 'required singer_id');
        return $validator;
    }

    public function validationIndex2(Validator $validator)
    {
        $validator
            ->notEmpty('hoge2', 'required singer_id');
        return $validator;
    }

    public function validationIndex3(Validator $validator)
    {
        $validator
            ->notEmpty('hoge2', 'required singer_id');
        return $validator;
    }

    //ドキュメントには他にもメソッドいたけどこれだけあれば最低限必要なことはできそう
}

```
index1.ctp
```
index1
= $this->Form->create($contactForm);?> = $this->Form->input('hoge1',['required' => false]);?> = $this->Form->input('hidden_key');?> = $this->Form->input('now');?> = $this->Form->submit('submit', ['name' => 'next_index2']);?> = $this->Form->end();?>

index2.ctp, (*10)

index2<br />
hoge1:= $this->request->data['hoge1'];?>

= $this->Form->create($contactForm);?>

= $this->Form->input('hoge2',['required' => false]);?>
= $this->Form->input('hidden_key');?>
= $this->Form->input('now');?>


= $this->Form->submit('back', ['name' => 'back_index1']);?>

= $this->Form->submit('next', ['name' => 'next_index3']);?>
= $this->Form->end();?>

index3.ctp, (*11)

index3<br />
hoge1:= $this->request->data['hoge1'];?><br />
hoge2:= $this->request->data['hoge2'];?><br />
= $this->Form->create($contactForm);?>

= $this->Form->input('hoge3',['required' => false]);?>
= $this->Form->input('hidden_key');?>
= $this->Form->input('now');?>


= $this->Form->submit('back1', ['name' => 'back_index1']);?>

= $this->Form->submit('back2', ['name' => 'back_index2']);?>

= $this->Form->submit('next', ['name' => 'next_save']);?>
= $this->Form->end();?>

The Versions

16/05 2016

dev-entitySetCorrespond

dev-entitySetCorrespond https://github.com/satthi/PostTransition

CakePHP PostTransition

  Sources   Download

MIT

The Requires

 

by Satoru Hagiwara

cakephp transition

25/04 2016

dev-master

9999999-dev https://github.com/satthi/PostTransition

CakePHP PostTransition

  Sources   Download

MIT

The Requires

 

by Satoru Hagiwara

cakephp transition

25/04 2016

3.1.2

3.1.2.0 https://github.com/satthi/PostTransition

CakePHP PostTransition

  Sources   Download

MIT

The Requires

 

by Satoru Hagiwara

cakephp transition

25/04 2016

dev-form_validation_multi

dev-form_validation_multi https://github.com/satthi/PostTransition

CakePHP PostTransition

  Sources   Download

MIT

The Requires

 

by Satoru Hagiwara

cakephp transition

25/04 2016

dev-patchEntityDoubleCheck

dev-patchEntityDoubleCheck https://github.com/satthi/PostTransition

CakePHP PostTransition

  Sources   Download

MIT

The Requires

 

by Satoru Hagiwara

cakephp transition

25/04 2016

3.1.1

3.1.1.0 https://github.com/satthi/PostTransition

CakePHP PostTransition

  Sources   Download

MIT

The Requires

 

by Satoru Hagiwara

cakephp transition

25/04 2016

dev-custom_parameter_add

dev-custom_parameter_add https://github.com/satthi/PostTransition

CakePHP PostTransition

  Sources   Download

MIT

The Requires

 

by Satoru Hagiwara

cakephp transition

15/03 2016

3.1

3.1.0.0 https://github.com/satthi/PostTransition

CakePHP PostTransition

  Sources   Download

MIT

The Requires

 

by Satoru Hagiwara

cakephp transition

15/03 2016

dev-now_position_check

dev-now_position_check https://github.com/satthi/PostTransition

CakePHP PostTransition

  Sources   Download

MIT

The Requires

 

by Satoru Hagiwara

cakephp transition

16/06 2015

3.0.x-dev

3.0.9999999.9999999-dev https://github.com/satthi/PostTransition

CakePHP PostTransition

  Sources   Download

MIT

The Requires

 

by Satoru Hagiwara

cakephp transition

16/06 2015

3.0

3.0.0.0 https://github.com/satthi/PostTransition

CakePHP PostTransition

  Sources   Download

MIT

The Requires

 

by Satoru Hagiwara

cakephp transition