cakephp flash error at Undefined variable: _SESSION [CORE/src/Network/Session.php, line 440]

三世轮回 提交于 2020-02-05 14:00:09

问题


I am following Article example from internet. Here is my Article Controller

namespace App\Controller;

class ArticlesController extends AppController {

    public function initialize() {
        parent::initialize();

        $this->loadComponent('Flash'); // Include the FlashComponent
    }

    public function index() {
        $articles = $this->Articles->find('all');
        $this->set(compact('articles'));
    }

    public function view($id) {
        $article = $this->Articles->get($id);
        $this->set(compact('article'));
    }

    public function add() {
        $article = $this->Articles->newEntity();
        if ($this->request->is('post')) {
            $article = $this->Articles->patchEntity($article, $this->request->data);
            if ($this->Articles->save($article)) {
                $this->Flash->success(__('Your article has been saved.'));
                return $this->redirect(['action' => 'index']);
            }
            $this->Flash->error(__('Unable to add your article.'));
        }
        $this->set('article', $article);
    }

    public function edit($id = null) {
        $article = $this->Articles->get($id);
        if ($this->request->is(['post', 'put'])) {
            $this->Articles->patchEntity($article, $this->request->data);
            if ($this->Articles->save($article)) {
                $this->Flash->success(__('Your article has been updated.'));
                return $this->redirect(['action' => 'index']);
            }
            $this->Flash->error(__('Unable to update your article.'));
        }

        $this->set('article', $article);
    }

    public function delete($id) {
        $this->request->allowMethod(['post', 'delete']);

        $article = $this->Articles->get($id);
        if ($this->Articles->delete($article)) {
            $this->Flash->success(__('The article with id: {0} has been deleted.', h($id)));
            return $this->redirect(['action' => 'index']);
        }
    }

}

when I save form I am getting below errors

Notice (8): Undefined variable: _SESSION [CORE/src/Network/Session.php, line 440]
Code Context
$name = 'Flash.flash'
$value = [
    'message' => 'Your article has been saved.',
    'key' => 'flash',
    'element' => 'Flash/success',
    'params' => []
]
$write = [
    'Flash.flash' => [
        'message' => 'Your article has been saved.',
        'key' => 'flash',
        'element' => 'Flash/success',
        'params' => []
    ]
]
Cake\Network\Session::write() - CORE/src/Network/Session.php, line 440
Cake\Controller\Component\FlashComponent::set() - CORE/src/Controller/Component/FlashComponent.php, line 99
Cake\Controller\Component\FlashComponent::__call() - CORE/src/Controller/Component/FlashComponent.php, line 139
Cake\Controller\Component\FlashComponent::success() - APP/Controller/ArticlesController.php, line 22
App\Controller\ArticlesController::add() - APP/Controller/ArticlesController.php, line 22
Cake\Controller\Controller::invokeAction() - CORE/src/Controller/Controller.php, line 411
Cake\Routing\Dispatcher::_invoke() - CORE/src/Routing/Dispatcher.php, line 114
Cake\Routing\Dispatcher::dispatch() - CORE/src/Routing/Dispatcher.php, line 87
[main] - ROOT/webroot/index.php, line 37

line 22 is $this->Flash->success(__('Your article has been saved.'));

Please note - I am just learning the basics and new to cakephp

来源:https://stackoverflow.com/questions/30896248/cakephp-flash-error-at-undefined-variable-session-core-src-network-session-ph

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!