直接定义空模块和空操作即可, 即建立一个EmptyAction.class.php, 代码:
01.
<?php
02.
03.
class
EmptyAction
extends
Action {
04.
05.
function
_empty(){
06.
header(
"HTTP/1.0 404 Not Found"
);
07.
$this
->display(
'Public:404'
);
08.
}
09.
10.
// 404
11.
function
index() {
12.
header(
"HTTP/1.0 404 Not Found"
);
13.
$this
->display(
'Public:404'
);
14.
}
15.
16.
}
17.
18.
?>
设置header头很重要, 不然的话返回的状态会是200.
该类对应Public模板目录下需要有名为404的页面模板.
除了 创建一个 EmptyAction 空模块 以外, 还要在每个控制器里面都要建立一个 _empty 方法才行。 每个控制器里面都有。 当然可以用 公用类来避免这样重复的操作。
建立一个公用类控制器:CommonAction.class.php
<?php
class CommonAction extends Action{
function _empty(){
header("Location: /404.html");
}
}
?>
然后 让其他控制器 都继承这个控制器, 如 IndexAction extends CommonAction 这样就行了。