Undefinid variables in template - Cake PHP 2.x

49 views Asked by At

I just migrate a cakephp 2.5 app to a server with PHP 7.2 (before server has 5.6 to 7.1), so I should update core (2.10) and finally get to show the app correctly but I'm having issues when urls with parameters loads.

The error is when I try to load a view passing a parameter in URL the controller are not passing the data correctly to the template and get errors like Undefined variable: menu [APP/View/Layouts/default.ctp, line 97, for all variables.

include - APP/View/Layouts/default.ctp, line 97 
View::_evaluate() - CORE/Cake/View/View.php, line 971 
View::_render() - CORE/Cake/View/View.php, line 933 
View::renderLayout() - CORE/Cake/View/View.php, line 546 
View::render() - CORE/Cake/View/View.php, line 481 
Controller::render() - CORE/Cake/Controller/Controller.php, line 968 
Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 200 
Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167 
[main] - APP/webroot/index.php, line 109 

I would appreciate your opinions. Thanks.

For example I call view localhost.com/administrator/Banners/editarBigHomePage?id=351 and the template is full with Notices of undefined variables, this just happens with URLS with parameters included.

1

There are 1 answers

0
Martin Guevara On

Here is the view with variables:

 public function editarBigHomePage()
    {
        $this->verificarUsuario();
        
        if(!empty($this->request->params["url"]['id'])){
            $id = $this->request->params["url"]['id'];
        $categorias = $this->Categoria->find('all');
        $this->set('categorias',$categorias);
        $ciudades = $this->Ciudade->find('all');
        $this->set('ciudades',$ciudades);
        $publicidad = $this->Publicidade->findById($id);
        $this->set('publicidad',$publicidad);
        $this->set('menu','publicity');
        $this->set('menu2','pase el menu por aqui');
        
        }
        if(!empty($this->request->data)){
            $dataPublicidad= $this->request->data["Publicidade"];
            $dataPublicidad["inhome"]=1; 
            if($this->Publicidade->save($dataPublicidad)){
                    $this->Session->setFlash('Publicity Edited','success');
                    return $this->redirect(array('controller'=>'Banners','action'=>'listarBigHomePage'),null,true);
                }else{
                    $this->Session->setFlash('Error Publicity No Edited');
                    return $this->redirect(array('controller'=>'Banners','action'=>'listarBigHomePage'),null,true);
                }
        }
    }