CakePHPに関するreggaepunchのブックマーク (2)

  • CakePHP2.xでSSL接続(https://)を強制させる | 14時の間食

    利用するのはSecurityコンポーネント。 CakePHPにもともと備わっているコンポーネントなので他所からのDLなどは一切不要です。 コントローラーに数行記述するだけ。 このお手軽さ。まずは、SSL接続を強制したいアクションのあるコントローラーで、Securityコンポーネントの使用を宣言します。 public $components = array('Security'); beforeFilter内に以下の記述を追加します。 ここではif文を使い、アクションがindexの時のみSSL接続が強制されるように設定しています。 コントローラー内の全てのアクションにSSL接続を強制したい時はこのif文は取り払って下さい。 public function beforeFilter(){ //indexのみSSL接続を強制 if ($this->action === 'index') { $t

    reggaepunch
    reggaepunch 2013/08/19
    なにこの便利機能。。。やばす。
  • [CakePHP] 例外時のレイアウトファイル変更 | HAPPY*TRAP

    CakePHPで例外を投げた時のレイアウトファイルを変更する方法です。 やり方はいろいろあると思いますが、今回は、ExceptionRendererクラスのサブクラスAppExceptionRendererを新規に作成して、出力時にレイアウトファイルを変更してみます。 app/Lib/Error/AppExceptionRenderer.php1 2 3 4 5 6 7 8 <?php App::uses('ExceptionRenderer', 'Error'); class AppExceptionRenderer extends ExceptionRenderer { protected function _outputMessage($template) { $this->controller->layout = 'custom'; // ここでレイアウトファイルを指定

    reggaepunch
    reggaepunch 2013/08/08
    確かに変更できた。
  • 1