调用非对象上的成员函数setFlash() [英] Call to a member function setFlash() on a non-object

查看:193
本文介绍了调用非对象上的成员函数setFlash()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习如何使用CakePHP,我在测试删除功能时遇到了一个错误。以下是错误讯息:

I'm currently learning how to use CakePHP and I encountered a bug while testing the Delete function. Here's the error message:


错误:在非对象

Error: Call to a member function setFlash() on a non-object


档案:C:\ xampp\htdocs\Forum4Alliances\app\Controller\PostsController.php

File:C:\xampp\htdocs\Forum4Alliances\app\Controller\PostsController.php


行:57

Line: 57



以下代码:

<?php
class PostsController extends AppController{
    public $helpers = array('Html','Form', 'Session');
    public $components = array('Session');

 //Part is omitted...

public function delete($id){
        if($this->request->is('get')){
            throw new MethodNotAllowedException();
        }
        if($this->Post->delete($id)){
            $this->Sessions->setFlash(__('The post with the id: %s has been deleted.', h($id)));
            return $this->redirect(array('action' => 'index'));
        }
    }
}
?>

如你所见,我包含了$ helpers和$ components。

As you see, I included the $helpers and $components. I couldn't find any answers past this point.

Cheers =)

推荐答案

您定义:

public $components = array('Session');

但使用比例:

$this->Sessions->setFlash(.. //**SessionS**

更正为:

$this->Session->setFlash

这篇关于调用非对象上的成员函数setFlash()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆