-
-
Notifications
You must be signed in to change notification settings - Fork 81
Comment feature #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Kishiko
wants to merge
5
commits into
pH-7:master
Choose a base branch
from
Kishiko:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ed2430a
Add comments feature
Kishiko 5beeb54
Add comment feature description
Kishiko f46d835
Enhancement after code review from the pull request
Kishiko 4ad2bf3
Reset database Config values
Kishiko 1e4972e
Fix 'Cannot redeclare \TestProject\Model\Comment class' error
Kishiko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* @author Serge Kishiko <[email protected]> | ||
* @copyright (c) 2015-2017, Pierre-Henry Soria. All Rights Reserved. | ||
* @license Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> | ||
* @link http://hizup.uk | ||
*/ | ||
|
||
namespace TestProject\Controller; | ||
|
||
class Comment extends Blog | ||
{ | ||
public function __construct() | ||
{ | ||
$this->oUtil = new \TestProject\Engine\Util; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you done what I tell you in my previous above comment, you can just remove the constructor here, so PHP will automatically call the parent constructor |
||
|
||
/** Get the Model class in all the controller class **/ | ||
$this->oUtil->getModel('Comment'); | ||
$this->oCommentModel = new \TestProject\Model\Comment; | ||
} | ||
|
||
public function add() | ||
{ | ||
if (!empty($_POST['add_comment'])) | ||
{ | ||
if (isset($_POST['id_post'], $_POST['content'], $_POST['author_name'])) | ||
{ | ||
$aData = array( | ||
'id_post' => $_POST['id_post'], | ||
'content' => $_POST['content'], | ||
'author_name' => $_POST['author_name'], | ||
'created_date' => date('Y-m-d H:i:s') | ||
); | ||
|
||
if ($this->oCommentModel->add($aData)) | ||
header('Location:' . ROOT_URL . '?p=blog&a=post&id=' . $_POST['id_post']); | ||
else | ||
$this->oUtil->sErrMsg = 'Whoops! An error has occurred! Please try again later.'; | ||
} | ||
else | ||
{ | ||
$this->oUtil->sErrMsg = 'All fields are required and the title cannot exceed 50 characters.'; | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
/** | ||
* @author Serge Kishiko <[email protected]> | ||
* @copyright (c) 2015-2017, Pierre-Henry Soria. All Rights Reserved. | ||
* @license Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> | ||
* @link http://hizup.uk | ||
*/ | ||
|
||
namespace TestProject\Model; | ||
|
||
class Comment extends Blog | ||
{ | ||
public function add(array $aData) | ||
{ | ||
$oStmt = $this->oDb->prepare('INSERT INTO Comments (idPost, content, authorName, createdDate) VALUES(:id_post, :content, :author_name, :created_date)'); | ||
return $oStmt->execute($aData); | ||
} | ||
|
||
public function getPostComments($iPostId) | ||
{ | ||
$oStmt = $this->oDb->prepare('SELECT * FROM Comments WHERE idPost = :postId'); | ||
$oStmt->bindParam(':postId', $iPostId, \PDO::PARAM_INT); | ||
$oStmt->execute(); | ||
return $oStmt->fetchAll(\PDO::FETCH_OBJ); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure you will need
$this->oUtil->getModel('Comment');
after$this->oUtil->getModel('Blog');
in order to include the file, since the SPL autoload isn't done for the Model classes.