我从CakePHP中获取了控制器中缺少的动作,但动作主页在我的控制器中定义,我为它做了一个空视图。
<?php
class PagesController extends AppController {
var $name = 'Pages';
var $uses = array('Event', 'News', 'Person', 'Signup', 'Workshop', 'Course');
function home() {
$this->layout = 'main';
}
function news() {
}
function events() {
}
}
?>
这是我的路线档案:
<?php
Router::connect('/login', array('controller' => 'users', 'action' => 'login'));
Router::connect('/admin/logout', array('controller' => 'users', 'action' => 'logout'));
Router::connect('/', array('controller' => 'pages', 'action' => 'home'));
答案 0 :(得分:2)
试试这个:
<?php
class PagesController extends AppController {
var $name = 'Pages';
var $uses = array('Event', 'News', 'Person', 'Signup', 'Workshop', 'Course');
function display() {
$path = func_get_args();
$count = count($path);
if (!$count) {
$this->redirect('/');
}
$page = $subpage = $title_for_layout = null;
if (!empty($path[0])) {
$page = $path[0];
}
if (!empty($path[1])) {
$subpage = $path[1];
}
$this->set(compact('page', 'subpage', 'title_for_layout'));
switch ($page) {
case 'home':
$this->_home();
$this->render('home');
break;
default:
$this->render(implode('/', $path));
}
}
function _home() {
$this->layout = 'main';
}
function news() {
}
function events() {
}
}
?>
并将此行放在路线的顶部:
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
答案 1 :(得分:1)
删除routes.php中的Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
并修改根路径路径:Router::connect('/', array('controller' => 'pages', 'action' => 'home'));
(这是可选的,但也许你会想要的)