1

私は PHP とデザイン パターンの初心者です。javascript と php を含むアプリケーションでユース ケース コントローラを実装する際に問題があります。学生プロフィールマネージャーのプロジェクトを作ろうとしています。教師が特定のセクションの生徒のマークをアップロードする「マークのアップロード」の使用例があります。そして、このユースケースでのシステム操作の責任を、UploadMarksEventHandler という名前のクラスに割り当てました。メソッドと属性について言及しただけで、まだ出力を生成することは想定されていません。コードは次のとおりです。

class UploadMarksHandler{
private $section;
private $central_storage; 
private $students = array();
private $cookie_name;
private isSelectSection = false;

function __construct(){

}

function login($teacher_id, $password){
    $password_temp=$this.centr/al_storage.getTeacherPassword($teacher_id);
    if($password_temp==$password){
        //set cookies
        setcookie($teacher_id, $password, time()+(60), "/");
    }
    else{
        echo "incorrect password";
    }
}

function selectSection($section){
    //check cookies
    $this->section=$this->central_storage.getSection($section);
    $this->is_section_selected=true;
    $this->students=$this->central_storage.getStudents($this->section);
}

function uploadMarks($student_id, $marks){
    //check cookies
}

function display_students(){
    //check cookies
    //display $this->students
}

function endUseCase(){
    //logout
    //destroy central storage object
    //destroy section object
    //destroy students object
    //destroy object
    }
}
?>

上記のコードは、アプリケーション ロジック レイヤー用です。UI レイヤーのユーザーは、login($teacher_id, $password)、uploadMarks($student_id, $marks) などの操作を実行します。これらの操作はそれぞれ、コントローラー クラス UploadMarksHandler の責任として与えられます。問題は、ユーザーが UI レイヤーから操作を生成することです。これは jquery でコーディングする予定です。ユーザーがブラウザの「Upload Marks」という名前のボタンを押したとします。このために、AJAX を使用して UploadMarksHandler オブジェクトを作成します。UIレイヤーをアプリケーションロジックレイヤーにマッピングする目的で使用されるmain.phpファイルで行います。

$upload_marks = new UploadMarksHandler(); //this is in main.php, which is called through AJAX

「マークのアップロード」ユース ケースの処理を担当する $upload_marks オブジェクトをインスタンス化した後、アプリケーションは UI レイヤーで次のシステム操作をリッスンする必要があります。ユーザーが「ログイン」という名前のボタンを押したとします。コントロールがクライアント側からサーバー側に戻ると、 $upload_marks オブジェクトが削除され、その状態が失われます。

PHP で MVC とコントローラーを適用することについて検索しましたが、私の問題に関して運がありませんでした。MVC フレームワークを使用する必要がありますか? どんな助けでも大歓迎です。

4

1 に答える 1