模板中未定义变量 - Cake PHP 2.x

问题描述 投票:0回答:1

我只是将 cakephp 2.5 应用程序迁移到 PHP 7.2 的服务器(在服务器有 5.6 到 7.1 之前),所以我应该更新核心(2.10)并最终正确显示应用程序,但在加载带参数的 url 时遇到问题.

错误是,当我尝试加载在 URL 中传递参数的视图时,控制器未将数据正确传递到模板,并出现类似 Undefined variable: menu [APP/View/Layouts/default.ctp, line 97, for所有变量。

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 

我很感激您的意见。谢谢。

例如,我调用视图 localhost.com/administrator/Banners/editarBigHomePage?id=351,模板中充满了未定义变量的通知,这仅发生在包含参数的 URL 上。

php cakephp cakephp-2.0
1个回答
0
投票

这是带有变量的视图:

 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);
                }
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.