このコードで何が問題なのかわかりません。私はそのセミコロンを考えましたが、どこにでも追加しました。リクエストを処理できないというこのコードをブラウザに表示すると、エラーが発生します。誰かが私にどこでミスをしたのか教えてもらえますか?私はプロパティ変数をヌル以外の値に設定しようとしましたが(単にそれらを宣言しています)、それはうまくいきませんでした。PHPクラスがレンダリングされないのはなぜですか?
<?php
class Controller {
/*add number of comments to quizComments tables'
*/
$dbConnection = null;
$userName = null;
$userScore = 0;
$currentQuestionIndex = 1;
function connectToDb() {
$mysql = 'mysql:dbname=cw;host=localhost';
$username = 'root';
$password = '';
try {
$this->dbConnection = new PDO($mysql, $username, $password);
echo 'connected to database';
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
};
function getComments ($commentTable, $questionID) {
$this->dbConnection->query("SELECT * FROM ('$commentTable') WHERE question_id = ('$questionID')");
};
function getQuestion ($questionTable, $questionID) {
$this->dbConnection->query("SELECT * FROM ('$questionTable') WHERE id = ('$questionID')");
};
function addComment ($commentTable, $questionID, $author, $content, $emailContact, $dateAdded) {
$this->dbConnection->query("INSERT INTO ('$commentTable') (question_id) VALUES ('$questionID')");
echo 'Thank you for your comment. We will approve it soon.';
};
function addQuestion ($questionTable, $question, $answer1, $answer2, $answer3, $answer4, $correctAnswerIndex, $explanation, $author, $shortDesc, $dateAdded) {
$this->dbConnection->query("INSERT INTO ('$questionTable') (question_id) VALUES ('$questionID')");
echo 'Thank you for submitting. We will approve it soon.';
};
function progressToNextQuestion($questionTable) {
$question = $this->getQuestion($questionTable, $this->currentQuestionIndex);
};
function startQuiz ($questionTable) {
if ($questionTable === 'QuizQuestionsBanking') {
$question = $this->getQuestion($questionTable, $this->currentQuestionIndex);
};
if ($questionTable === 'QuizQuestionsTrading') {
$question = $this->getQuestion($questionTable, $this->currentQuestionIndex);
};
};
function checkAnswer ($questionTable, $questionID, $chosenIndex) {
$question = $this->getQuestion($questionTable, $questionID);
$correctAnswerIndex = $question['solutionIndex'];
if ($correctAnswerIndex === $chosenIndex) {
$this->score++;
$this->currentQuestionIndex++;
$this->saveCurrentScore();
$this->progressToNextQuestion($questionTable);
} else {
echo 'Wrong. Please try again.';
};
};
function saveCurrentScore() {
/* 1. make table called 'Leaderboard'
* 2. insert into table 'username,score' values (username,score)
*/
};
function get15MostRecentQuestion() {
/*sort descending, date */
};
function get15HighestRatedQuestion() {
/* show different metric from usual: divide rating over # of votes*/
/* sort descending, rating
*
* */
};
function get15MostCommentedQuestion() {
/* sort number_of_comments descending
*/
};
function getTop10Contributors() {
};
function rateQuestion() {
};
function getLeaderboard() {
/* SELECT * from Leaderboard
*/
};
};
?>
と交換してください、あなたはあなたのウェブサーバのエラーログに取得エラーを投稿することができますか? – Fredster
プロパティを正しく宣言する必要があります。* public、protected、privateのいずれかのキーワードを使用して定義され、その後に通常の変数宣言*(マニュアルを参照)が続きます。 – jeroen
カスタムコンストラクタはありません。構文上のエラーがない限り、それは問題ありません。あなたの質問から欠けているものは、あなたがこのクラスを呼び出す方法と、あなたが得る正確なエラーです。 –