Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
framework-web:symfony:td6 [2018/03/20 18:11] – créée jcheron | framework-web:symfony:td6 [2019/08/31 14:21] (Version actuelle) – modification externe 127.0.0.1 | ||
---|---|---|---|
Ligne 4: | Ligne 4: | ||
|< 100% >| | |< 100% >| | ||
- | | {{: | + | | {{: |
< | < | ||
Ligne 11: | Ligne 11: | ||
===== Objectifs ===== | ===== Objectifs ===== | ||
- | - Bases symfony + Doctrine | + | - Factorisation du code |
- | - Requêtes Ajax, Composants | + | - Réutilisation |
- | ===== Partie 2 : Administration | + | ===== Prise en main ===== |
+ | |||
+ | Vous pouvez au choix : | ||
+ | * Partir de votre propre projet et y inclure les éléments du projet Github | ||
+ | * Partir du projet GitHub pour y intégrer vos propres fonctionnalités (recommandé) | ||
+ | |||
+ | A partir du dossier du projet, exécuter : | ||
+ | <sxh bash ; | ||
+ | composer update | ||
+ | </ | ||
+ | |||
+ | Dans le fichier **.env**, ajuster la valeur de la variable **DATABASE_URL**. | ||
+ | |||
+ | Démarrer le serveur (Mysql) et le serveur http de dévelopement : | ||
+ | <sxh bash ; | ||
+ | php bin/console server: | ||
+ | </ | ||
+ | |||
+ | ===== Factorisation du code ===== | ||
+ | |||
+ | ==== Doctrine repositories ==== | ||
+ | Les repositories de chacun des models héritent de **MainRepository**, | ||
+ | |||
+ | < | ||
+ | [MainRepository|+get(); | ||
+ | </ | ||
+ | |||
+ | Chaque Repository héritant de MainRepository a juste à définir dans son constructeur la classe métier auquel il correspond : | ||
+ | <sxh php; | ||
+ | <?php | ||
+ | |||
+ | namespace App\Repository; | ||
+ | |||
+ | use Symfony\Bridge\Doctrine\RegistryInterface; | ||
+ | use App\Entity\Developer; | ||
+ | |||
+ | class DeveloperRepository extends MainRepository{ | ||
+ | public function __construct(RegistryInterface $registry){ | ||
+ | parent:: | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Services Semantic ==== | ||
+ | Les services Semantic de chacun des models héritent de **SemanticGui**, | ||
+ | |||
+ | < | ||
+ | [SemanticGui|+dataTable(objects type); | ||
+ | </ | ||
+ | |||
+ | Chaque Classe Gui dérivée de **SemanticGui** doit logiquement redéfinir les méthodes **dataTable** et **dataForm**. | ||
+ | |||
+ | ==== CRUD contrôleurs ==== | ||
+ | Chaque contrôleur pilotant une classe métier hérite de **CrudController**, | ||
+ | |||
+ | {{: | ||
+ | |||
+ | * Chaque Repository héritant de MainRepository utilise les méthodes protégées de **CrudController**. | ||
+ | * Le constructeur doit initialiser par injection de dépendances une instance de **MainRepository** et de **SemanticGui** dérivées dans son constructeur. | ||
+ | <sxh php; | ||
+ | <?php | ||
+ | class DevelopersController extends CrudController{ | ||
+ | |||
+ | public function __construct(DevelopersGui $gui, | ||
+ | $this-> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | } | ||
+ | /** | ||
+ | * @Route("/ | ||
+ | */ | ||
+ | public function index(){ | ||
+ | return $this-> | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * @Route("/ | ||
+ | */ | ||
+ | public function refresh(){ | ||
+ | return $this-> | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * @Route("/ | ||
+ | */ | ||
+ | public function edit($id){ | ||
+ | return $this-> | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * @Route("/ | ||
+ | */ | ||
+ | public function add(){ | ||
+ | return $this-> | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * @Route("/ | ||
+ | */ | ||
+ | public function update(Request $request){ | ||
+ | return $this-> | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * @Route("/ | ||
+ | */ | ||
+ | public function deleteConfirm($id){ | ||
+ | return $this-> | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * @Route("/ | ||
+ | */ | ||
+ | public function delete($id, | ||
+ | return $this-> | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Fonctionnalités à implémenter ===== | ||
+ | ==== CRUD ==== | ||
+ | |||
+ | <wrap mytodo> | ||
+ | |||
+ | Pour les models **Tag**, **Step**, **Task**, ajouter les fonctionnalités de base CRUD : | ||
+ | * Listage des instances dans une table | ||
+ | * Suppression | ||
+ | * Modification | ||
+ | * Ajout | ||
+ | |||
+ | Consignes : | ||
+ | * Respecter la logique fonctionnelle et structurelle (implémentation) mise en place dans le projet initial | ||
+ | * Factoriser au mieux le code | ||
+ | |||
+ | ==== Route index ==== | ||
+ | |||
+ | <wrap mytodo> | ||
+ | |||
+ | Modifier la route **index**, pour qu' | ||
+ | |||
+ | {{: | ||