CakePHP2系です。
スマホ用URLの場合、スマホに合わせた404エラーページを表示したいです。
1系の古い情報しかなく、うまくいかないため質問させて頂きました。
スマホの場合◯◯/smart/〜〜というURLになるので、下記のように判定させていますが、PCのエラーページが表示されてしまいます。
app_error.phpの記述がおかしいのだと思いますが、調べても理解できず、お力をお借りしたく存じます。
何卒、アドバイスよろしくお願い致します。
PHP
1//app/app_error.php 2<?php 3class AppError extends ErrorHandler { 4 5 public function error404($params) { 6 if (isset($this->params['prefix']) && $this->params['prefix'] == 'smart') { 7 $this->controller->layout = 'smart_error'; 8 parent::error404($params); 9 } else { 10 $this->controller->layout = 'pc_error'; 11 } 12}
Viewは端折っていますが下記のようになっています。
HTML
1//View/Errors/smart_error400.ctp 2<?php $this->layout = "smart_error"; ?> 3 4 <h2 class="title">404 ご指定のページは見つかりませんでした</h2> 5 6 <p class="message">エラー:このページは存在していないURLです。</p>
Layout
HTML
1//View/Layouts/smart_error.ctp 2<!doctype html> 3<html> 4<head> 5<meta charset="utf-8"> 6<?php echo $this->element('smart_header'); ?> 7</head> 8<body> 9 10<div id="container"> 11 12<?php echo $this->element('smart_header_menu'); ?> 13 14<?php echo $this->fetch('content'); ?> 15 16<?php echo $this->element('smart_footer'); ?> 17</div> 18</div> 19 20</body> 21</html>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。