[PHP-NOTES] note 130583 added to function.define

[email protected] ("[email protected]") Thu, 18 Dec 2025 18:40:56 +0000
Newsgroups php.notes
Message-ID <[email protected]>
3. Le Contrôleur (Controller)
Il fait le lien entre l'URL, les données du Repository et l'affichage de la Vue.

PHP
// app/controller/Product.php
namespace app\controller;
use app\model\entity\ProductEntity;
use app\model\repository\DbProductRepository;

class Product {
    private $repository;

    public function __construct() {
        $this->repository = new DbProductRepository();
    }

    // Affiche le formulaire de modification
    public function update(array $params) {
        $id = (int)$params[0];
        $product = $this->repository->findById($id);
        require "view".DIRECTORY_SEPARATOR."updateProduct.php";
    }

    // Traite la soumission du formulaire
    public function updateProduct() {
        $id = (int)$_POST['id'];
        $product = new ProductEntity();
        $product->setName($_POST['name']);
        $product->setPrice((float)$_POST['price']);
        $product->setQuantity((int)$_POST['quantity']);

        $this->repository->update($id, $product);
        header("Location: " . CFG["siteURL"] . "Home");
    }
}
4. Configuration et Sécurité
config.inc.php
PHP
define("HOME", __DIR__ . DIRECTORY_SEPARATOR);
const CFG = array(
    "db" => array(
        "host" => HOME . ".." . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR,
        "database" => "madb.db",
        "login" => null, "password" => null,
        "options" => array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION),
        "exec" => "PRAGMA foreign_keys = ON;"
    ),
    "siteURL" => "http://localhost/~votre_login/mvc/app/"
);
Sécurisation des dossiers
Assure-toi que chaque dossier sensible (config, data, model, system) possède un fichier .htaccess pour bloquer l'accès direct :

Apache
# Dans app/data/.htaccess par exemple
order deny,allow
deny from all
----
Server IP: 206.189.2.9
Probable Submitter: 2a01:cb05:83c6:e400:f0a3:4e6f:3d4a:5c72
----
Manual Page -- https://php.net/manual/en/function.define.php
Edit        -- https://main.php.net/note/edit/130583
Del: integrated  -- https://main.php.net/note/delete/130583/integrated
Del: useless     -- https://main.php.net/note/delete/130583/useless
Del: bad code    -- https://main.php.net/note/delete/130583/bad+code
Del: spam        -- https://main.php.net/note/delete/130583/spam
Del: non-english -- https://main.php.net/note/delete/130583/non-english
Del: in docs     -- https://main.php.net/note/delete/130583/in+docs
Del: other reasons-- https://main.php.net/note/delete/130583
Reject      -- https://main.php.net/note/reject/130583
Search      -- https://main.php.net/manage/user-notes.php