src/Controller/CommentController.php
public function CreateAction()
  {
    // Checks if the user is connected
    if (Session::islogged())
    {
      // Creates the $data array to store the new comment
      $data['article_id']   = $_GET['id'];
      $data['content']      = $_POST['content'];
      $data['created_date'] = $_POST['date'];
      $data['user_id']      = $_SESSION['user']['id'];

      // Creates the comment
      ModelFactory::get('Comment')->create($data);

      // Creates a valid message to confirm the creation of a new comment
      htmlspecialchars(Session::createAlert('New comment created successfully !', 'valid'));

      // Redirects to the view readArticle
      $this->redirect('article!read', ['id' => $_GET['id']]);
    }
    else {
      // Creates a fail message to ask to be connected
      htmlspecialchars(Session::createAlert('You must be logged in to add a comment...', 'cancel'));
    }
    // Redirects to the view loginUser
    $this->redirect('user!login');
  }
public function CreateAction()
  {
    // Checks if the user is connected
    if (Session::islogged())
    {
      // Creates the $data array to store the new comment
      $data['article_id']   = $_GET['id'];
      $data['content']      = $_POST['content'];
      $data['created_date'] = $_POST['date'];
      $data['user_id']      = $_SESSION['user']['id'];

      // Creates the comment
      ModelFactory::get('Comment')->create($data);

      // Creates a valid message to confirm the creation of a new comment
      htmlspecialchars(Session::createAlert('New comment created successfully !', 'valid'));

      // Redirects to the view readArticle
      $this->redirect('article!read', ['id' => $_GET['id']]);
    }
    else {
      // Creates a fail message to ask to be connected
      htmlspecialchars(Session::createAlert('You must be logged in to add a comment...', 'cancel'));
    }
    // Redirects to the view loginUser
    $this->redirect('user!login');
  }
public function CreateAction ( ) { // Checks if the user is connected if ( Session :: islogged ( ) ) { // Creates the $data array to store the new comment $ data [ 'article_id' ] = $ _GET [ 'id' ] ; $ data [ 'content' ] = $ _POST [ 'content' ] ; $ data [ 'created_date' ] = $ _POST [ 'date' ] ; $ data [ 'user_id' ] = $ _SESSION [ 'user' ] [ 'id' ] ; // Creates the comment ModelFactory :: get ( 'Comment' ) -> create ( $ data ) ; // Creates a valid message to confirm the creation of a new comment htmlspecialchars ( Session :: createAlert ( 'New comment created successfully !' , 'valid' ) ) ; // Redirects to the view readArticle $ this -> redirect ( 'article!read' , [ 'id' => $ _GET [ 'id' ] ] ) ; } else { // Creates a fail message to ask to be connected htmlspecialchars ( Session :: createAlert ( 'You must be logged in to add a comment...' , 'cancel' ) ) ; } // Redirects to the view loginUser $ this -> redirect ( 'user!login' ) ; }
********************\
Creates a new comment
******************** \ Creates a new comment