错误:在非对象文件上调用成员函数setFlash():C:\ wamp \ www \ CakePHP \ app \ Controller \ PublishersController.php行:28

时间:2015-03-12 06:36:43

标签: cakephp

<?php
class PublishersController extends AppController
{

    public function index()
    {
        $this->set("publishers",
            $this->Publisher->find("all", array('order' => 'company_name ASC')));
    }

    public function view($id = null)
    {
        $this->Publisher->id = $id;
        $this->set('publisher', $this->Publisher->read());
    }

    function edit($id = null)
    {
        $this->Publisher->id = $id;
        if (empty($this->data))
        {
            $this->data = $this->Publisher->findById($id);
        }
        else
        {
            if ($this->Publisher->save($this->data))
            {
                $this->Session->setFlash('Publisher Updated Successfully');
                $this->redirect(array('action' => 'index'));
            }
        }
    }
}

?>

1 个答案:

答案 0 :(得分:5)

看起来你还没有加载Session类。

在AppController或PublisherController中,您需要添加以下内容:

public $components = array('Session');

那应该解决它。