コード例 #1
0
ファイル: Sessions.php プロジェクト: nirix/dreamer
 public function destroyAction()
 {
     return $this->respondTo(function ($format) {
         if (Request::isXhr()) {
             $resp = $this->jsonResponse(['success' => 'You are now logged out']);
         } else {
             $resp = $this->redirectTo('root');
         }
         return $resp->addCookie('dreamer', '', time(), '/');
     });
 }
コード例 #2
0
ファイル: Catchall.php プロジェクト: nirix/dreamer
 public function currentUserAction()
 {
     if ($this->currentUser) {
         return $this->respondTo(function ($format) {
             if (Request::isXhr()) {
                 return $this->jsonResponse(['id' => $this->currentUser->id, 'username' => $this->currentUser->username]);
             }
         });
     } else {
         return $this->show404();
     }
 }
コード例 #3
0
ファイル: Controller.php プロジェクト: avalonphp/avalon
 /**
  * Easily respond to different request types.
  */
 protected function respondTo(callable $callback)
 {
     // Is this an XMLHttpRequest? If not, use the request extension or fallback to HTML.
     $format = Request::isXhr() ? 'js' : Request::$properties->get('extension', 'html');
     return $callback($format);
 }