1. Go to this page and download the library: Download samphp/framework 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/ */
// app/controllers/ProductController.php
class ProductController extends Controller
{
public function index()
{
$productModel = $this->model('Product');
$products = $productModel->getAll();
$this->view('product/index', ['products' => $products]);
}
public function create()
{
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
Security::verifyCsrf($_POST['csrf_token']);
$name = Security::sanitize($_POST['name']);
// ... save to database
}
$this->view('product/create');
}
}
// app/models/Product.php
class Product extends Model
{
public function getAll()
{
$stmt = $this->db->query("SELECT * FROM products ORDER BY id DESC");
return $stmt->fetchAll();
}
public function create($data)
{
$stmt = $this->db->prepare("INSERT INTO products (name, price) VALUES (?, ?)");
return $stmt->execute([$data['name'], $data['price']]);
}
}
<!-- app/views/product/index.php -->
// In any controller method
class DashboardController extends Controller
{
public function index()
{
AuthMiddleware::handle(); // Requires login
// RoleMiddleware::handle(['admin', 'editor']); // Role-based access
$this->view('dashboard/index');
}
}
// In a controller — set a flash message
Session::flash('success', 'Product created successfully!');
$this->redirect('/product');
// In a view — display it
if ($msg = Session::getFlash('success')):
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.