【发布时间】:2011-11-03 14:44:16
【问题描述】:
我需要在“/cake/libs/controller/pages_controller.php”中添加新功能,但我不想直接更改它,因为它是核心 cakephp 的一部分,因此我所做的就是复制“pages_controller.php”。 php” 进入“app/controllers/”,然后我添加了新功能,但出现了一些错误,例如“控制器 PagesController 中未定义动作显示”。
注意事项:
- /cake/libs/controller/pages_controller.php确实有函数display()
- /app/controllers/pages_controller.php 没有 display()
有什么问题?为什么我会收到这个错误?
这是 /app/controllers/pages_controller.php:
<?php
class PagesController extends AppController {
var $name = 'Pages';
var $helpers = array('Html', 'Session');
var $uses = array();
function display_no_layout() {
$this->autoLayout = false; // new line
$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];
}
if (!empty($path[$count - 1])) {
$title_for_layout = Inflector::humanize($path[$count - 1]);
}
$this->set(compact('page', 'subpage', 'title_for_layout'));
$this->render(implode('/', $path));
}
}
我的 /app/config/routers.php:
Router::connect('home/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect('/successfully', array('controller' => 'pages', 'action' => 'display_no_layout', 'successfully'));
【问题讨论】:
-
显示 /app/controllers/pages_controller.php
标签: cakephp