IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MVC PHP Discussion :

Initialisation modulaire et bootstraping


Sujet :

MVC PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre Expert
    Avatar de s.n.a.f.u
    Homme Profil pro
    Développeur Web
    Inscrit en
    Août 2006
    Messages
    2 760
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Août 2006
    Messages : 2 760
    Par défaut Initialisation modulaire et bootstraping
    Bonjour,

    Je continue dans mon exploitation des modules sous ZF.
    Ca se passe pas mal, mais je voudrais maintenant utiliser (et comprendre) une initialisation modulaire, c'est à dire spécifique à un module.

    Pour exemple, je voudrais initialiser un layout suivant le module utilisé, ou me connecter à une base spécifique, etc...

    Mon premier problème est au niveau du bootstrap: d'après mes tests, ZF exécute TOUS les Module_Bootstrap !

    Dans mon appli, j'ai un module "private" et un module "admin"
    Dans Private_Bootstrap et Admin_Bootstrap (qui étendent bien sûr Zend_Application_Module_Bootstrap), j'ai juste codé une méthode _initTest qui affiche un message : 'hello private' ou 'hello admin'.
    Quelle ne fut pas ma surprise de voir les deux messages lorsque j'entre une url http://monsite.fr/private/controller/action

    => le module Admin est bootstrappé alors qu'il n'est pas utilisé. Est-ce normal ?

    Si oui, je ne peux utiliser les Module_Bootstrap pour mon initialisation spécifique.
    Quelle est alors la bonne manière de procéder ?

    D'avance merci,

    SNAF

  2. #2
    Membre Expert
    Avatar de s.n.a.f.u
    Homme Profil pro
    Développeur Web
    Inscrit en
    Août 2006
    Messages
    2 760
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Août 2006
    Messages : 2 760
    Par défaut
    Je viens de me mettre à jour en 1.8.4 et il n'y a pas de changement.

    mes deux classes :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    <?php
    class Private_Bootstrap extends Zend_Application_Module_Bootstrap {
     
        protected function _initMsg() {
            Zend_Debug::dump('hello private');
        }
     
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    class Admin_Bootstrap extends Zend_Application_Module_Bootstrap {
     
        protected function _initMsg() {
            Zend_Debug::dump('hello admin');
        }
     
    }
    Les deux bootstrap sont exécutés quelle que soit l'url et je vois mes deux hello

    le fichier de config application.ini utilisé par Zend_Application :
    Code ini : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    production]
    phpSettings.display_startup_errors = 0
    phpSettings.display_errors = 0
     
    bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
    bootstrap.class = "Bootstrap"
     
    resources.frontController.baseUrl               = "/monsite"
    resources.frontController.controllerDirectory   = APPLICATION_PATH "/controllers"
    resources.frontController.moduleDirectory       = APPLICATION_PATH "/modules"
    resources.frontController.defaultModule         = "default"
     
    resources.modules = ""
     
    resources.layout.layout     = "layout"
    resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
     
    resources.view.encoding = "UTF-8"
     
    resources.db.adapter               = "PDO_SQLITE"
    resources.db.params.dbname         = APPLICATION_PATH "/db.db3"
    resources.db.isDefaultTableAdapter = true
    Le Bootstrap et son autoLoad :
    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
     
        protected function _initAutoload() {
            $autoloader = new Zend_Application_Module_Autoloader(array(
                'namespace' => '',
                'basePath'  => dirname(__FILE__)
            ));
            return $autoloader;
        }
     
        protected function _initDb() {
            $db = $this->getPluginResource('db')->getDbAdapter();
            $db->setFetchMode(Zend_Db::FETCH_OBJ);
            Zend_Db_Table_Abstract::setDefaultAdapter($db);
            Zend_Registry::set('db', $db);
        }
     
    }
    Quelqu'un pourrait-il déjà me dire pourquoi tous les boostraps sont lancés ?

  3. #3
    Membre Expert
    Avatar de s.n.a.f.u
    Homme Profil pro
    Développeur Web
    Inscrit en
    Août 2006
    Messages
    2 760
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Août 2006
    Messages : 2 760
    Par défaut
    Ah, ah ! Je crois que je tiens un article valable !
    There is some confusion regarding the resources initialized by the module bootstraps. Many people think that these resource methods and plugins are executed only if the request maps to a controller belonging to this module. This is not the case. As the sequence diagram below shows, these methods and plugins are executed well before the front controller is dispatched. Thus, any code in the module bootstraps affects the whole application. This is contrary to most people’s expectations, mostly because the term module bootstrap implies otherwise. Rather than a module bootstrap, one should think of them as scattered parts of the application bootstrap that are organized per module. This limits the usefulness of the module bootstrap to registering plugins, helpers, helper paths and routes as they are the things that are unlikely to conflict with other bootstraps. However, these are plenty useful by themselves, and module-specific behavior can be defined through a plugin registered by the module bootstrap. But that’s a topic for another post.
    => http://monzee.wordpress.com/2009/06/...ons-in-zf-1-8/

  4. #4
    Membre Expert
    Avatar de Eusebe
    Inscrit en
    Mars 2006
    Messages
    1 992
    Détails du profil
    Informations personnelles :
    Âge : 47

    Informations forums :
    Inscription : Mars 2006
    Messages : 1 992
    Par défaut
    Citation Envoyé par s.n.a.f.u Voir le message
    Ah, ah ! Je crois que je tiens un article valable !

    => http://monzee.wordpress.com/2009/06/...ons-in-zf-1-8/
    En effet, voilà une belle réponse

  5. #5
    Membre Expert
    Avatar de s.n.a.f.u
    Homme Profil pro
    Développeur Web
    Inscrit en
    Août 2006
    Messages
    2 760
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Août 2006
    Messages : 2 760
    Par défaut
    There is some confusion regarding the resources initialized by the module bootstraps. Many people think that these resource methods and plugins are executed only if the request maps to a controller belonging to this module. This is not the case. As the sequence diagram below shows, these methods and plugins are executed well before the front controller is dispatched. Thus, any code in the module bootstraps affects the whole application.
    Je pense que cela mériterait d'être précisé dans un tuto ou autre, parce que j'ai un peu galèré pour trouver cette info.

  6. #6
    Membre Expert
    Avatar de aityahia
    Homme Profil pro
    CIEPTAL CARS SPA
    Inscrit en
    Mars 2006
    Messages
    1 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Algérie

    Informations professionnelles :
    Activité : CIEPTAL CARS SPA
    Secteur : Transports

    Informations forums :
    Inscription : Mars 2006
    Messages : 1 938
    Par défaut
    Bonjour,

    Si j'ai bien compris il est donc inutile d'initialiser les bootstrap des différents modules, vu qu'il sont tous lancés

Discussions similaires

  1. [ZF 1.9] Initialiser la classe Bootstrap
    Par mister_sood dans le forum Autres composants
    Réponses: 2
    Dernier message: 11/09/2009, 16h46
  2. Initialisation et bootstrap
    Par gtraxx dans le forum MVC
    Réponses: 21
    Dernier message: 20/01/2009, 14h07
  3. [servlet] initialisation d'objets
    Par tiPouick dans le forum Servlets/JSP
    Réponses: 11
    Dernier message: 05/08/2003, 12h12
  4. Initialisation de XMLModule
    Par Sylvain Leray dans le forum XMLRAD
    Réponses: 10
    Dernier message: 01/04/2003, 10h08
  5. initialisation Directinput avec delphi
    Par Madmaxx dans le forum DirectX
    Réponses: 1
    Dernier message: 21/02/2003, 17h37

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo