/** * Remove all comments. * * @return void */ public function removeAllAction() { $isPosted = $this->request->getPost('doRemoveAll'); if (!$isPosted) { $this->response->redirect($this->request->getPost('redirect')); } $comments = new \Phpmvc\Comment\CommentsInSession(); $comments->setDI($this->di); $comments->deleteAll(); $this->response->redirect($this->request->getPost('redirect')); }
<?php // Bootstrapping (i.e. configurations, create framework object etc.) require __DIR__ . '/config_with_app.php'; // Creating a controller service for comments $di->set('CommentController', function () use($di) { $controller = new Phpmvc\Comment\CommentController(); $controller->setDI($di); return $controller; }); // Creating a model service for comments $di->set('comments', function () use($di) { $comments = new \Phpmvc\Comment\CommentsInSession(); $comments->setDI($di); $comments->setContext($di->request->getCurrentUrl()); return $comments; }); // Defining routes $app->router->add('', function () use($app) { $app->theme->setTitle('Lite om mig'); $app->views->add('me/page', ['content' => $app->textFilter->doFilter($app->fileContent->get('about.md'), 'shortcode, markdown'), 'byline' => $app->textFilter->doFilter($app->fileContent->get('byline.md'), 'shortcode, markdown')]); // Adds the possibility to post comments on the page \mife\Comment\CommentSetup::initComments($app); }); $app->router->add('redovisning/kmom1', function () use($app) { $app->theme->setTitle('Redovisning'); $app->views->add('me/page', ['content' => $app->textFilter->doFilter($app->fileContent->get('kmom1.md'), 'shortcode, markdown'), 'byline' => $app->textFilter->doFilter($app->fileContent->get('byline.md'), 'shortcode, markdown')]); // Adds the possibility to post comments on the page \mife\Comment\CommentSetup::initComments($app); }); $app->router->add('redovisning/kmom2', function () use($app) {
/** * Updates a comment. * * @param id of comment to save. * * @return void */ public function updateAction($id) { $isPosted = $this->request->getPost('doUpdate'); $key = $this->request->getPost('key'); if (!$isPosted) { $this->response->redirect($this->request->getPost('redirect')); } $comment = ['content' => $this->request->getPost('content'), 'name' => $this->request->getPost('name'), 'web' => $this->request->getPost('web'), 'mail' => $this->request->getPost('mail'), 'timestamp' => time(), 'ip' => $this->request->getServer('REMOTE_ADDR')]; $comments = new \Phpmvc\Comment\CommentsInSession($key); $comments->setDI($this->di); $comments->update($id, $key, $comment); $this->response->redirect($this->request->getPost('redirect')); }