mvc model
TRANSCRIPT
![Page 2: Mvc Model](https://reader036.vdocument.in/reader036/viewer/2022080211/559079171a28ab8c6f8b4594/html5/thumbnails/2.jpg)
MVC
• Bắt đầu từ những năm 1970. Lần đầu công bố vào 1978.
• MVC là viết tắt của Model – View – Controller
• Chia ứng dụng thành 3 thành phần–Model– View– Controller
![Page 3: Mvc Model](https://reader036.vdocument.in/reader036/viewer/2022080211/559079171a28ab8c6f8b4594/html5/thumbnails/3.jpg)
Model
•Model giao tiếp với cơ sở dữ liệu.
•Model nhận và lưu trữ trong một cơ sở dữ liệu.
•Ví dụ, một đối tượng Product có thể nhận thông tin từ Database
•* Nếu thay đổi CSDL thì chỉ cần thay đổi Model
MY SQL-SQL-XML-Text
![Page 4: Mvc Model](https://reader036.vdocument.in/reader036/viewer/2022080211/559079171a28ab8c6f8b4594/html5/thumbnails/4.jpg)
View•Hiển thị giao diện ứng dụng
•Giao diện người dùng được tạo ra từ dữ liệu trong các đối tượng Model
•Ví dụ, có thể chỉnh sửa phần hiển thị của một bảng Products
![Page 5: Mvc Model](https://reader036.vdocument.in/reader036/viewer/2022080211/559079171a28ab8c6f8b4594/html5/thumbnails/5.jpg)
Controller
• Controller điều khiển sự tương
tác của người dùng. Xử lý
request từ url và form
• Làm việc với các đối tượng
• Chọn một đối tượng View để
hiển thị giao diện người dùng
![Page 6: Mvc Model](https://reader036.vdocument.in/reader036/viewer/2022080211/559079171a28ab8c6f8b4594/html5/thumbnails/6.jpg)
![Page 10: Mvc Model](https://reader036.vdocument.in/reader036/viewer/2022080211/559079171a28ab8c6f8b4594/html5/thumbnails/10.jpg)
Model.php• <?php
function dbconnect() { static $connect=null; if($connect==null){ $connect=mysql_connect("localhost","root","root"); mysql_select_db("autoshop"); } return $connect; } function closedb() { mysql_close($con); } function getuser($usersId) { $query=mysql_query("SELECT * FROM users WHERE usersId='$usersId'",dbconnect()); return mysql_fetch_assoc($query);
}?>
![Page 11: Mvc Model](https://reader036.vdocument.in/reader036/viewer/2022080211/559079171a28ab8c6f8b4594/html5/thumbnails/11.jpg)
View.php• <?php
echo $users["usersName"];?><form method="POST" action="<?php echo $_SERVER["PHP_SELF"];?>"><input type="text" name="usersId"/><input type="submit" value="Submit"/></form>
![Page 12: Mvc Model](https://reader036.vdocument.in/reader036/viewer/2022080211/559079171a28ab8c6f8b4594/html5/thumbnails/12.jpg)
Control.php• <?php
require_once("../mvc/model.php"); if($_SERVER["REQUEST_METHOD"]=="POST") { header("HTTP/1.1 301 Moved Permanently"); header("location:".$_SERVER["PHP_SELF"]."?usersId=".$_POST["usersId"]); exit; }else {
$users=getuser($_GET["usersId"]); require("../mvc/view.php"); }?>