问题
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