Chapitre 7 : Notion de Framework PHP
Framework = cadriciel
Ensemble de conposants logiciels fournissant un cadre de conception
Quelques frameworks connus :
CodeIgniter, Symfony, Laravel, Phalcon, Cake PHP, Zend, Yii
Les frameworks permettent d'intégrer facilement certains concepts ou fonctionnalités dans une application :
Architecture MVC
MVC est un patron de conception (design pattern) permettant de séparer les différentes composantes d'une application suivant leur rôle :
- M = Modèle (logique et classes métier)
- V = Vue (Partie présentation, interface utilisateur)
- C = Contrôleur (Logique applicative, contrôle, synchronisation)
Routage, logique applicative
Mappage objet/relationel
Vues
- Rôle d'affichage uniquement, reçoivent les données du contrôleur
- Utilisation de moteur de template (cache)
1 2 3 4 5 6 7 8 9 10 11 12 13 |
< table class = 'table table-striped' > < thead >< tr >< th colspan = '3' >{{model}}</ th ></ tr ></ thead > < tbody > {% for object in objects %} < tr > < td >{{object.toString()|raw}}</ td > < td class = 'td-center' >< a class = 'btn btn-primary btn-xs' href = '{{baseHref~"/frm/"~object.getId()}}' >...</ a ></ td > < td class = 'td-center' >< a class = 'btn btn-warning btn-xs' href = '{{baseHref~"/delete/"~object.getId()}}' >X</ a ></ td > </ tr > {% endfor %} </ tbody > </ table > < a class = 'btn btn-primary' href = '{{config["siteUrl"]~baseHref~"/frm"}}' >Ajouter...</ a > |
Scripts côté client
- Généré en PHP
- Dans les contrôleurs, puis insérés dans la vue
1 2 3 4 5 6 7 |
public function index() { $this ->loadView( "main/vHeader.html" , array ( "infoUser" =>Auth::getInfoUser())); $this ->loadView( "main/vDefault.html" ); $this ->loadView( "main/vFooter.html" ); Jquery::getOn( "click" , ".btAjax" , "Sample/ajaxSample" , "#response" ); echo Jquery::compile(); } |