Changing top of a cakephp page only

Asked

Viewed 89 times

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.

2 answers

1

I don’t remember very well, I haven’t worked with Cakephp for a long time, but one of the possible solutions 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 the view:

// de um arquivo view
$this->layout = 'loggedin';

0

I would create equal parts Elements aiming at reuse and create two layouts or even if it is only a page would use: $this->layout = false; and put everything in the view but using the Elents anyway.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.