0
I picked up a website for maintenance and he’s on CakePHP
(framework that does not work). It does some routes for all the files that are inside the folder view/pages
Routes.php
foreach(scandir('../View/Pages') as $path){
if (is_dir('../View/Pages/' . $path)) {
foreach(scandir('../View/Pages/' . $path) as $subPath){
if(pathinfo($subPath, PATHINFO_EXTENSION) == "ctp"){
$name = pathinfo($subPath, PATHINFO_FILENAME);
Router::connect('/' . $path . '/' .$name, array('controller' => 'pages', 'action' => 'display', $path . '/' . $name));
}
}
} else {
if(pathinfo($path, PATHINFO_EXTENSION) == "ctp"){
$name = pathinfo($path, PATHINFO_FILENAME);
Router::connect('/'.$name, array('controller' => 'pages', 'action' => 'display', $name));
}
}
}
The page is accessible normally, but they sent a change so I can do where the logo of a page (ctp.) will be different from other pages. The problem begins because the site puts the same top, navbar and footer to the pages and only changes even the middle. Like I don’t know how the CakePHP
so I don’t know how to create a header.ctp
customized and just put to run on the page ctp.. I’ll put the controller pages below for you to visualize how it is:
Pagescontroller.php
<?php
App::uses('AppController', 'Controller');
class PagesController extends AppController {
public $uses = array();
public function display() {
$path = func_get_args();
$count = count($path);
if (!$count) {
return $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'));
try {
$this->render(implode('/', $path));
} catch (MissingViewException $e) {
if (Configure::read('debug')) {
throw $e;
}
throw new NotFoundException();
}
}
public function admin_display() {
$path = func_get_args();
$count = count($path);
if (!$count) {
return $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'));
try {
$this->render(implode('/', $path));
} catch (MissingViewException $e) {
if (Configure::read('debug')) {
throw $e;
}
throw new NotFoundException();
}
}
}
I need a light to know how to change only the top. If you need me to post some controller, model or view here just ask, because I don’t know what you need to fix this change.