私は先週、OOP と MVC について読んで学んでいるので、正しい方向に進んでいるかどうか知りたいです。
これが私が現在持っているものの例です:
index.php Apache mod_rewrite (.htaccess) から渡された URL を解析します。このファイルには、最初にサイト固有の設定と定義済みの変数も含め、次に関連するコントローラー ファイルとビューを含めます。
<?php
// Include the site specific settings
require 'includes/settings.php';
// Include the HTML page header
require LIBPATH . 'views/page_header.php';
//Code to parse the url passed in from mod_rewrite
require LIBPATH . 'controllers/' . $require_url . '.inc.php';
require LIBPATH . 'views/' . $require_url . '.php';
// Include the HTML page footer
require PUBLICPATH . 'includes/page_footer.php';
?>
コントローラーに移ります。このファイルでは、フォーム $_POST が設定されていることを確認してから、モデル (クラス) を呼び出します。
<?php
if (isset($_POST)) {
$loginUser = new User();
$loginUser->email = $_POST['email'];
$loginUser->password = $_POST['password'];
$returnArray = (json_decode($loginUser->select(), true));
$_SESSION['userID'] = $loginUser->userID;
$_SESSION['firstName'] = $loginUser->firstName;
$_SESSION['lastName'] = $loginUser->lastName;
$_SESSION['email'] = $loginUser->email;
// Redirect code to admin area of the site
}
?>
モデル(クラス)コード:
<?php
// Basically I'm interacting with the database and returning the data in a JSON encoded array. This is always where I check to make sure that values are set and correct before doing the database queries.
?>
これは MVC と PHP OOP を使用する正しい方法ですか?
ご意見ありがとうございます。