tutorial to show MVC pattern.
Divide your problem in layers. Model for your data. Views for your data presentation. Controller for join the layers.
The view can be divided in two parts: templates and some other functionalities.
# user_view.tpl
<h1>Users</h1>
<?php foreach($users as $user): ?>
Name: <?php echo $user['name']; ?> <br/>
Age: <?php echo $user['age']; ?> <br/>
<hr/>
<?php endforeach; ?>
# UserView.php
<?php
return function ($vars) {
$users = $vars['users'];
include "user_view.tpl";
};
# UserModel.php
<?php
return function($filter) {
return [
[
"name" => "Peter",
"age" => 20
]
];
};
# UserControl.php
<?php
// get model
$userModel = require 'UserModel.php';
// get view
$userView = require 'UserView.php';
// load users
$users = $userModel(["limit" => 10]);
// show users
$userView(['users' => $users]);
Regards,
@rafageist
Thanks, but I want to beginning create a small size ecommerce project by using MVC oop. I look for tutorial or any useful resource.
Обсуждают сегодня