CakePHP - 控制器中未定义操作
我从 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'));
I'm getting the missing action in controller from CakePHP, but the action home is defined in my controller and I've made an empty view for it.
<?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() {
}
}
?>
This is my routes file:
<?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'));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
删除routes.php中的
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
并修改根路径路由:
Router::connect('/', array('controller' => 'pages', 'action' => 'home'));
(它是可选,但也许你会想要)remove
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
in your routes.phpand modify the root path route:
Router::connect('/', array('controller' => 'pages', 'action' => 'home'));
(it's optional, but maybe you'll want that)试试这个:
并将这一行放在路线的顶部:
Try this:
And place this line at the top of your routes: