PHP code example of linkorb / answers-client
1. Go to this page and download the library: Download linkorb/answers-client library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
linkorb / answers-client example snippets
use Linkorb\AnswersClient\Client as Client;
use Linkorb\AnswersClient\Question as Question;
// get the client
$client = new Client(
'<Host>',
'<Username>',
'<Password>'
);
// Create Question
$question = new Question( $client );
$question->setQuestion(<Question>);
$question->setDescription(<Description>);
$question->setTopicId(<topic id>);
try {
$question->create();
} catch( Exception $e ) {
echo $e->getMessage();
}
$question->setQuestion(<question>);
try {
$question->update();
} catch( Exception $e ) {
echo $e->getMessage();
}
// Get Question
$question = new Question( $client );
$question->get(<Question id>);
$answers = $question->getAnswers();
var_dump($answers);
$comments = $question->getComments();
var_dump($comments);
$votes = $question->getVotes();
var_dump($votes);
// Update question
$question = new Question( $client );
$question->get(<Question id>);
$question->setQuestion(<Question>);
$question->setDescription(<Description>);
try {
$question->update();
} catch( Exception $e ) {
echo $e->getMessage();
}
// Delete question
$question = new Question( $client );
$question->get(<Question Id>);
try {
$question->delete();
} catch( Exception $e ) {
echo $e->getMessage();
}
//Comment
$question = new Question( $client );
$question->get(<Question id>);
try {
$question->comment(<Comment>);
} catch( Exception $e ) {
echo $e->getMessage();
}
// Vote
$question = new Question( $client );
$question->get(<Question id>);
try {
$question->vote();
} catch( Exception $e ) {
echo $e->getMessage();
}
// Create Answer
$answer = new Answer( $client );
$answer->setQuestionId( <Question id> );
$answer->setAnswer( <Answer id> );
try {
$answer->create();
} catch( Exception $e ) {
echo $e->getMessage();
}
// Get Answer
$answer = new Answer( $client );
$answer->get( <Answer id> );
$comments = $answer->getComments();
var_dump($comments);
$votes = $answer->getVotes();
var_dump($votes);
// Update Answer
$answer = new Answer( $client );
$answer->get( <Answer id> );
$answer->setAnswer(<Answer>);
try {
$answer->update();
} catch( Exception $e ) {
echo $e->getMessage();
}
// Delete Answer
$answer = new Answer( $client );
$answer->get(<Answer id>);
try {
$answer->delete();
} catch( Exception $e ) {
echo $e->getMessage();
}
// Commnent Answer
$answer = new Answer( $client );
$answer->get(<Answer Id>);
try {
$answer->comment(<Comment>);
} catch( Exception $e ) {
echo $e->getMessage();
}
// Vote Answer
$answer = new Answer( $client );
$answer->get(<Answer Id>);
try {
$answer->vote();
} catch( Exception $e ) {
echo $e->getMessage();
}
// Get comment
$comment = new Comment( $client );
$comment->get(<Comment Id>);
$votes = $comment->getVotes();
var_dump($votes);
// Update comment
$answer = new Answer( $client );
$answer->get(<Answer id>);
$answer->setAnswer(<Answer>);
try {
$answer->update();
} catch( Exception $e ) {
echo $e->getMessage();
}
// Delete comment
$comment = new Comment( $client );
$comment->get(<Comment id>);
try {
$comment->delete();
} catch( Exception $e ) {
echo $e->getMessage();
}
// Vote comment
$comment = new Comment( $client );
$comment->get(<Comment id>);
try {
$comment->vote();
} catch( Exception $e ) {
echo $e->getMessage();
}
// Delete comment
$vote = new Vote( $client );
$vote->get(<Vote id>);
try {
$vote->delete();
} catch( Exception $e ) {
echo $e->getMessage();
}