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

Zend Framework PHP Discussion :

require_once ' ' pour chaque fichier dans mon models


Sujet :

Zend Framework PHP

  1. #1
    Rédacteur

    Homme Profil pro
    Technical Lead Salesforce
    Inscrit en
    Février 2009
    Messages
    563
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Technical Lead Salesforce

    Informations forums :
    Inscription : Février 2009
    Messages : 563
    Points : 1 667
    Points
    1 667
    Par défaut require_once ' ' pour chaque fichier dans mon models
    Bonjour, je souhaiterais bien configurer mon fichier index.php parce qu'actuellement, pour chaque fichier que j'ai dans mon répertoire 'models', je dois faire un require_once ' ' de celui-ci pour pouvoir l'utiliser sinon j'ai un message comme quoi ma classe n'existe pas.

    Bizarrement, dans mon fichier index.php, je déclare bien l'endroit où est situé mon répertoire models:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    // Ensure library/ is on include_path
    set_include_path(implode(PATH_SEPARATOR, array(
        realpath(APPLICATION_PATH . '/../../Zend1.11/library'),
        realpath(APPLICATION_PATH . '/models'),
        realpath(APPLICATION_PATH . '/forms'),
        get_include_path(),
    )));
    Mon fichier index.php est situé à la racine du projet:
    . nomProjet
    - application/
    - library/
    - public/
    - test/
    - index.php
    - Mes articles
    - Consultant technique Salesforce
    - Salesforce Certified Administrator
    - Salesforce Certified Platform App Builder
    - Salesforce Certified Developper I
    - Salesforce Certified Sales Cloud
    - Salesforce Certified Service Cloud

  2. #2
    Membre éprouvé
    Avatar de 5h4rk
    Homme Profil pro
    CTO at TabMo
    Inscrit en
    Février 2011
    Messages
    813
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : CTO at TabMo
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2011
    Messages : 813
    Points : 1 297
    Points
    1 297
    Par défaut
    Bonjour,
    Tu souhaites utiliser l autoload ?

  3. #3
    Rédacteur

    Homme Profil pro
    Technical Lead Salesforce
    Inscrit en
    Février 2009
    Messages
    563
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Technical Lead Salesforce

    Informations forums :
    Inscription : Février 2009
    Messages : 563
    Points : 1 667
    Points
    1 667
    Par défaut
    Oui mais quand j'avais essayé avec la documentation, j'obtiens une erreur comme quoi je dois utiliser un namespace:
    Fatal error: Uncaught exception 'Zend_Loader_Exception' with message 'Initial definition of a resource type must include a namespace' in /home/***/***/***/library/Zend/Loader/Autoloader/Resource.php on line 283
    Mon code dans l'index.php:
    Code : 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
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
     
    <?php
    if (!defined('APPLICATION_PATH')) {
        define('APPLICATION_PATH', realpath(__DIR__ . '/../application'));
    }
     
    if (!defined('APPLICATION_ENV')) {
        $environment = getenv('APPLICATION_ENV');
        if (false === $environment) {
            $environment = 'production';
        }
        define('APPLICATION_ENV', $environment);
        unset($environment);
    }
     
    set_include_path(
        realpath(APPLICATION_PATH . '/../library') . PATH_SEPARATOR .
        get_include_path()
    );
     
    // Ensure library/ is on include_path
    set_include_path(implode(PATH_SEPARATOR, array(
        realpath(APPLICATION_PATH . '/forms'),
        realpath(APPLICATION_PATH . '/models'),
        get_include_path(),
    )));
     
    require_once 'Zend/Application.php';
    $application = new Zend_Application(
        APPLICATION_ENV,
        array(
        	'config' => array(
                APPLICATION_PATH . '/configs/application.ini',
                APPLICATION_PATH . '/configs/application-local.ini'
            )
        )
    );
     
    $resourceLoader = new Zend_Loader_Autoloader_Resource(array(
    	'basePath'      => '/application/',
        'namespace'     => '',
        'resourceTypes' => array(
            'form' => array(
                'path'      => 'forms/',
                'namespace' => 'Form',
            ),
            'model' => array(
                'path'      => 'models/',
            ),
        ),
    ));
     
    $application->bootstrap()
                ->run();
    Je voudrais que ca me charge toute mon application pour que je n'ai plus à me soucier de faire des require_once.
    - Mes articles
    - Consultant technique Salesforce
    - Salesforce Certified Administrator
    - Salesforce Certified Platform App Builder
    - Salesforce Certified Developper I
    - Salesforce Certified Sales Cloud
    - Salesforce Certified Service Cloud

  4. #4
    Membre actif Avatar de DarkSeiryu
    Homme Profil pro
    Développeur Java
    Inscrit en
    Janvier 2009
    Messages
    425
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Janvier 2009
    Messages : 425
    Points : 275
    Points
    275
    Par défaut
    Yo.

    Ta config' est un peu différente de la mienne, du coup j'suis un peu paumé. Je te donne le code de mon index.php ainsi que de mon bootstrap principal pour une application modulaire.

    index.php
    Code : 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
    23
    24
    25
    26
    27
    28
    29
    30
    <?php
     
    error_reporting(E_ALL);
    ini_set("display_errors", 1);
    ini_set('soap.wsdl_cache_enabled', '0'); // Pour supprimer la mise en cache du fichier WSDL.
     
    // Define path to application directory
    defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
     
    // Define application environment
    defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
     
    // Ensure library/ is on include_path
    set_include_path(implode(PATH_SEPARATOR, array(
        realpath('/home/wwwroot/library'),
        realpath('/home/wwwroot/library/font'),
    	realpath(APPLICATION_PATH.'/modules'),
        get_include_path(),
    )));
     
    define('ADMIN', 'admin'); // Pour savoir si un utilisateur est admin.
     
    require_once 'Zend/Loader/Autoloader.php';
    $autoloader = Zend_Loader_Autoloader::getInstance();
    $autoloader->setFallbackAutoloader(true);
    $autoloader->suppressNotFoundWarnings(true);
     
    // Create application, bootstrap, and run.
    $application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
    $application->bootstrap()->run();
    Bootstrap.php
    Code : 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
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    <?php
     
    class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
     
    	/**
    	 * Récupère les données du application.ini.
    	 * Zend_Registry l'objet contenant les données dans le application.ini.
    	 */
    	protected function _initConfiguration(){
            $config = new Zend_Config($this->getOptions(), APPLICATION_ENV);
     
            $this->_config 		= $config;
            $this->_registry	= Zend_Registry::getInstance();
            $this->_registry->set('config', $config);
     
            return $config;
        }
     
    	/**
         * Permet de déclarer les Namespaces utiles à l'application.
         * @return void
         */
        protected function _initDefaultNamespace() {
            $moduleLoaders = array();
     
            // Default.
    		$default = new Zend_Application_Module_Autoloader(array(
    		    'namespace' => 'Default_',
    		    'basePath'  => APPLICATION_PATH . '/modules/default',
    		));
    		$default->addResourceType('lib', 'library/', 'Lib');
     
    		// Admin.
    		$admin = new Zend_Application_Module_Autoloader(array(
    		    'namespace' => 'Admin_',
    		    'basePath'  => APPLICATION_PATH . '/modules/admin',
    		));
    		$admin->addResourceType('lib', 'library/', 'Lib');
     
    	    // Ajout des namespaces.
    	    $moduleLoaders['Default'] = $default;
    	    $moduleLoaders['Admin'] = $admin;
     
    		return $moduleLoaders;
        }
     
        /**
         * Initialize databases.
         * @return Zend_Db::factory
         */
        protected function _initDb() {
            // On charge notre fichier de configuration.
            $config = new Zend_Config($this->getOptions());
     
            // On essaie de faire une connexion a la base de données.
            try {
                $db = Zend_Db::factory($config->db);
                //on test si la connexion se fait
                $db->getConnection();
            }
            catch (Exception $e) {
                exit($e->getMessage());
            }
     
            // On stoque notre dbAdapter dans le registre.
            Zend_Registry::set('db', $db);
     
            return $db;
        }
     
    	protected function _initAuth() {
     
    		$storage = new Zend_Auth_Storage_Session();
    		$sessionNamespace = new Zend_Session_Namespace($storage->getNamespace());
    		$sessionNamespace->setExpirationSeconds(3600);
     
    		$this->_registry->set('session', $sessionNamespace);
     
    		$auth = Zend_Auth::getInstance();
    		$auth->setStorage($storage);
     
    		$acl = new Default_Model_AccesRules($auth);
    		$this->_registry->set('auth', $auth);
    		$this->_registry->set('acl', $acl);
     
    		$authPlugin = new Common_Plugin_Auth_GenerateurCertifs($auth, $acl);
     
    		$frontController = Zend_Controller_Front::getInstance();
    		$frontController->registerPlugin($authPlugin);
     
    		return $auth;
    	}
     
        /**
         * Initialise la view.
         */
        protected function _initView(){
     
    //    	Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');
     
            $view = new Zend_View();
            $view->setEncoding('ISO-8859-1');
     
            $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
            Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
     
            Zend_Layout::startMvc(array('layout' => 'layout' ,'layoutPath' => APPLICATION_PATH . "/layouts/scripts/"));
    		$mvc = Zend_Layout::getMvcInstance();
     
    		$this->_registry->set('mvc', $mvc);
     
            return $view;
        }
     
        /**
         * Initialise les view helpers.
         */
        protected function _initViewHelpers() {
            $this->bootstrap('layout');
     
            $layout = $this->getResource('layout');
            $view   = $layout->getView();
     
            $view->doctype('XHTML1_STRICT');
    //        $view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
    		$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=ISO-8859-1');
            $view->headTitle()->setSeparator(' - ');
            $view->headTitle('Générateur de certificats');
        }
    }
    J'espère que ça t'aidera...

    DarkSeiryu

Discussions similaires

  1. Réponses: 1
    Dernier message: 23/04/2007, 14h04
  2. upload des fichiers dans mon serveur
    Par abdou.sahraoui dans le forum Servlets/JSP
    Réponses: 2
    Dernier message: 29/05/2006, 09h32
  3. [Upload] Problème pour uploader un fichier dans mon code
    Par Peuplarchiste dans le forum Langage
    Réponses: 2
    Dernier message: 27/05/2006, 09h48
  4. Réponses: 1
    Dernier message: 17/05/2005, 20h50
  5. [VB.NET] Taille differente pour chaque colonne dans DATAGRID
    Par stephane93fr dans le forum Windows Forms
    Réponses: 14
    Dernier message: 12/01/2005, 16h50

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