====== Modèle ======
Création d'une table simple pour débuter :
CREATE TABLE articles (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
body TEXT,
published BOOLEAN DEFAULT FALSE,
created DATETIME,
modified DATETIME
) CHARSET=utf8;
Générer le modèle, le contrôleur et les vues :
cd /var/www/mon_site
sudo bin/cake bake all articles
sudo chown -R www-data:www-data ./src
(Je fais un **chown** simplement pour que les fichiers soient éditables avec //Codiad// qui est un éditeur web installé sur le même serveur.)
===== src/Model/Entity/Article.php =====
true,
'title' => true,
'slug' => true,
'body' => true,
'published' => true,
'created' => true,
'modified' => true,
'user' => true
];
}
===== src/Model/Table/ArticleTable.php =====
setTable('articles');
$this->setDisplayField('title');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsTo('Users', [
'foreignKey' => 'user_id',
'joinType' => 'INNER'
]);
}
}