I need to add new functionalities into “/cake/libs/controller/pages_controller.php” but I do not want to change it directly because it is part of the core’s cakephp, therefor what I did was to copy “pages_controller.php” into “app/controllers/” and then I added new functions but I’m getting some errors like “The action display is not defined in controller PagesController”.
Notes:
- /cake/libs/controller/pages_controller.php indeed has function display()
- /app/controllers/pages_controller.php does not have display()
What is the problem? why I’m getting that error?
this is the /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));
}
}
My /app/config/routers.php:
Router::connect('home/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect('/successfully', array('controller' => 'pages', 'action' => 'display_no_layout', 'successfully'));
When you create
it overrides
So
display()needs to be in your PagesController, given you are routing to it. You probably want to keep thedisplay()as copied and write something like