0

私は先週、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 を使用する正しい方法ですか?

ご意見ありがとうございます。

4

1 に答える 1

0

フレームワークを使用することをお勧めします。Code Igniterを見てください。これは最高の MVC フレームワークではありませんが、私が php で使用した唯一のフレームワークです。

于 2012-11-13T14:54:54.993 に答える