我有一个控制器中的404页面的调用:
$this->set('title','Page Not Found');
$this->cakeError('error404');
它使用我的自定义404页面,但忽略标题.标题设置为“错误”.
你如何设置?
public.ctp(我没有使用空白)
<?php header('Content-type: text/html; charset=UTF-8') ;?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<?php echo $html->charset('utf-8'); ?>
<title><?php echo $title_for_layout?></title>
app_controller.php
function beforeRender() {
if($this->name == 'CakeError') {
$this->set('title_for_layout', 'Page Not Found');
$this->layout = 'public';
}
}
行动
$this->pageTitle = 'Page Not Found';
$this->cakeError('error404');
解决方法:
I just answered this question in another topic.
您必须使用以下代码在应用程序的根目录中创建error.php:
<?php
class AppError extends ErrorHandler {
function error404($params) {
$this->controller->set('title_for_layout', 'Your Title');
parent::error404($params);
}
}