2016-04-20 17 views
0

を働いていないコンポーネントのFlash:プロバイダコントローラ機能のレビューではCakePHP3 - 私のアプリのコントローラで

class AppController extends Controller 
{ 
    public function initialize() 
    { 
     parent::initialize(); 
     $this->loadComponent('Flash'); 
     $this->loadComponent('RequestHandler'); 
     $this->loadComponent('Cookie'); 
    } 

}

public function review() { 
     if ($this->request->is('post')) { 
      $userId = $this->request->session()->read('Auth.User.UserId'); 
      $partnerId = $this->request->data('PartnerId'); 
      $content = $this->request->data('Content'); 
      $commentTable = TableRegistry::get('Comment'); 
      $comment = $commentTable->newEntity(); 
      $comment->UserId = $userId; 
      $comment->PartnerId = $partnerId; 
      $comment->Content = $content; 
      $comment->CreatedBy = $userId; 
      $comment->UpdatedBy = $userId; 
      $comment->Source = $this->request->session()->read('Auth.User.LoginBy'); 
      if ($commentTable->save($comment)) { 
       $this->Flash->success('Thank you for review!'); 
      } else { 
       $this->Flash->error('So Sorry your review was failed! Please notify for us to fixed this problem!'); 
      } 
      $this->redirect('provider/' . $partnerId); 
     } 
    } 
  • ユーザーがレビューの成功が、フラッシュを提出」doesnのtショー。しかし、私はこのプロジェクトでテストとFlashの作業のためにyoutube(https://www.youtube.com/watch?v=eASSNS1f3V4)から別のプロジェクトのチュートリアルを作成しようとしています。
  • 私の英語については申し訳ありませんが、私を助けてください。どうもありがとうございました!
+0

plzのチェックに役立つことを願っています。 org/2.0/ja/core-libraries/components/flash.html –

+0

ありがとうございます@トーナマーク、私はそれを解決しました。 –

答えて

0

私はケーキをはっきり理解できないので、これは私のせいです。私は、Cakeのdefautレイアウトを変更して、FlashがHTMLのfolder Element/Flash/**。ctpをcakeスタイルのCSSで呼び出すようにした。したがって、メッセージボックスは表示されません。

+0

問題を解決しましたか? –

0

私はそれがあなたの質問への答えではないのですが、ここにコードを改善するためのいくつかのヒントですよ:

public function review(){ 
     if($this->request->is('post')){ 
      $commentTable = TableRegistry::get('Comment'); 
      $comment = $CommentTable->newEntity(); 
      $userId = $this->Auth->user('id'); 
      $comment->patchEntity($comment, $this->request->data);  
      $comment->patchEntity($comment, ['CreatedBy' => $userId, 'UserId' => $userId, 'UpdatedBy' => $userId, 'Source' => $userId]); 
      if($commentTable->save($comment)){ 
       //something 
      } else { 
       //something 
      } 
     } 
    } 

あなたが同じを使用する場合は、1時間にエンティティ内のすべてのフォームの変数を置くことができますこの行を実行して、フォームの入力のための列名:

$userId = $this->Auth->user('id'); 

$comment->patchEntity($comment, $this->request->data); 

あなたのコントローラでユーザーセッション変数にアクセスしたい場合は、これを使用することができます手動エンティティ内の他の変数を入れたい場合はその後、あなたは次のように行うことができます

://book.cakephp:

$comment->patchEntity($comment, ['CreatedBy' => $userId, 'UserId' => $userId, 'UpdatedBy' => $userId, 'Source' => $userId]); 

は、それはあなたにこのURLはhttp上

関連する問題