CakePHP3 コントローラーでステータスコード(statusCode)を設定する方法です。
1 2 3 4 5 | // 403 Forbidden $this->response->statusCode(403); // 404 Not Found $this->response->statusCode(404); |
CakePHP3歴 1年のWEBエンジニアの備忘メモです。ブログ内容はCakePHP3.5 (PHP7.1) で検証しています。
投稿日:2017年11月29日 更新日:
CakePHP3 コントローラーでステータスコード(statusCode)を設定する方法です。
1 2 3 4 5 | // 403 Forbidden $this->response->statusCode(403); // 404 Not Found $this->response->statusCode(404); |
執筆者:管理人
関連記事
CakePHP3 Template用にsetした値を参照する方法
CakePHP3 Template用にsetした値を参照する方法です。
1 2 3 4 5 6 | <?php $aaa = 'test'; $this->set('bbb', $aaa); var_dump($this->viewVars['bbb']); // 出力結果: test |
コントローラーでのリダイレクト処理。 ◯ 同じコントローラーのアクション指定
1 | return $this->redirect(['action' => 'index']); |
◯ 異なるコントローラーのアクション指定 [crayon …
CakePHP3 コントローラーにてURL生成(Router)する方法
◯ CakePHP3 コントローラーにてURL生成(Router)方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <?php use Cake\Routing\Router; //// アクセスURL例:https://test.com/contact?test // カレントパス(ドメイン含む) Router::url(NULL, true); -> https://test.com/contact // カレントパスのみ(ドメイン含まない) Router::url(); -> /contact // クエリストリングを含むパス(ドメイン含む) Router::reverse($this->request, true); -> https://test.com/contact?test // クエリストリングを含むパス(ドメイン含まない) Router::reverse($this->request); -> /contact?test // 【その他】 サーバー変数($_SERVER) $_SERVER['REQUEST_URI']; -> /contact?test |
CakePHP3 ImageMagickで写真(画像)リサイズするサンプルコード
◯ CakePHP3 ImageMagickで写真(画像)リサイズするサンプルコードです。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | // サンプルコード // 縦: xxxpx -> 600px // 写真パス $photo_file_path = '写真パス'; // 写真読み込み $imagick_img = new \Imagick($photo_file_path); // 写真サイズ取得 $img_width = $imagick_img->getImageWidth(); $img_height = $imagick_img->getImageHeight(); // 写真リサイズ // 縦サイズ601px以上だったら縦サイズ600pxにリサイズ $max_height = 600; if (!empty($img_width) && !empty($img_height) && ($max_height < $img_height)) { // リサイズ処理 if (!$imagick_img->resizeImage(0, $max_height, \Imagick::FILTER_POINT, 1)) { // resizeImageエラー } } // 写真上書き保存 if (!$imagick_img->writeImage($photo_file_path)) { // 上書き保存エラー } // Imagick clear $imagick_img->clear(); |
関連リンク:CentO …