1. Go to this page and download the library: Download ultimecreation/php-mvc library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ultimecreation / php-mvc example snippets
class UserModel extends Model
{
public function getAllUsers()
{
$req = $this->bdd->prepare('select * from users');
$req->execute();
return $req->fetchAll();
}
}
3. Création d'un contrôleur src > controllers > SomeControllersController
// $data = array(
// 'template' => 'custom'
// );
class HomeController extends Controller
{
public function index()
{
// get the modelName and call a method
$users = $this->getModel('UserModel')->getAllUsers()
// passing data to the front using $data
$data['users'] = $users;
return $this->renderView('pages/index',$data);
}
}
4.Défissition d'une route src > Route > routes.php
class Routes
{
public static function getRoutes()
{
/**
* route format url|goto
* url String (ie: '/',....)
* Controller/method/params (ie: 'HomeController','index')
* params Regex (ie: '(\d+)','(\W+)')
* examples
* ========
* array('url' => '/test/(\d+)', 'goto' => array('TestController', 'index')),
* array('url' => '/test/save', 'goto' => array('TestController', 'save')),
* array('url' => '/retest/update', 'goto' => array('RetestController', 'update')),
* array('url' => '/retest/delete', 'goto' => array('RetestController', 'delete')),
*/
return [
array('url' => '/admin', 'goto' => array('AdminHomeController', 'index')),
array('url' => '/db-setup', 'goto' => array('DbSetupController', 'index')),
array('url' => '/', 'goto' => array('HomeController', 'index')),
];
}
}
5. Création d'une Vue src > views > someFolder(inc,pages,admin,templates) > someFileName.php
6. Récupération des variables provenant du contrôleur
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
echo $data['someData'];
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.