Change top of a cakephp-only page

0

I have taken a site to do maintenance and it is in CakePHP (framework that does not work). It makes some routes for all files that are inside the 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 usually accessible, but they have sent a change to make where the one-page logo (upcreditos.ctp) will be different from the other pages. The problem starts because the site puts the same top, navbar and footer for the pages and only changes the middle. Since I do not know how CakePHP works then I do not know how to create a custom header.ctp and just put it to run on the upcreditos.ctp page. I'll put the controller pages below for you to see 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 a controller, model or view here, just ask, because I do not know what you need to resolve this change.

    
asked by anonymous 03.06.2016 / 20:19

2 answers

1

I do not remember very well, I have not worked with CakePHP for some time, but one possible solution is to work with multiple layouts .

For the specific view, you can set a different layout for it in the controller and adapt it:

// de um controller
public function view() {
    // códigos
    $this->layout = 'admin';
}

Or from the view:

// de um arquivo view
$this->layout = 'loggedin';
    
03.06.2016 / 20:35
0

I would create equal parts elements for reuse and create two layouts or even if only one page would use: $this->layout = false; and would put everything in the view but using the elements anyway.

    
05.06.2016 / 05:56