Précédent   Forum des professionnels en informatique > PHP > Outils > Zend > Zend Framework
Zend Framework Forum d'entraide sur la programmation PHP avec Zend Framework. Avant de poster -> FAQ ZF, Cours ZF
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 03/02/2012, 18h00   #1
Nouveau Membre du Club
 
Inscription : février 2009
Messages : 261
Détails du profil
Informations forums :
Inscription : février 2009
Messages : 261
Points : 30
Points : 30
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 :
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:
Citation:
. nomProjet
- application/
- library/
- public/
- test/
- index.php
absot est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/02/2012, 13h47   #2
Modérateur
 
Homme Loïc
Développeur Web
Inscription : février 2011
Messages : 682
Détails du profil
Informations personnelles :
Nom : Homme Loïc
Âge : 26
Localisation : France, Hérault (Languedoc Roussillon)

Informations professionnelles :
Activité : Développeur Web
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : février 2011
Messages : 682
Points : 1 047
Points : 1 047
Bonjour,
Tu souhaites utiliser l autoload ?
5h4rk est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/02/2012, 15h10   #3
Nouveau Membre du Club
 
Inscription : février 2009
Messages : 261
Détails du profil
Informations forums :
Inscription : février 2009
Messages : 261
Points : 30
Points : 30
Oui mais quand j'avais essayé avec la documentation, j'obtiens une erreur comme quoi je dois utiliser un namespace:
Citation:
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 :
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.
absot est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/02/2012, 13h29   #4
Membre confirmé
 
Avatar de DarkSeiryu
 
Homme Mickaël
Développeur Web
Inscription : janvier 2009
Messages : 408
Détails du profil
Informations personnelles :
Nom : Homme Mickaël
Âge : 23
Localisation : France, Haute Savoie (Rhône Alpes)

Informations professionnelles :
Activité : Développeur Web

Informations forums :
Inscription : janvier 2009
Messages : 408
Points : 234
Points : 234
Envoyer un message via MSN à DarkSeiryu
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 :
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 :
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
DarkSeiryu est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 01h23.


 
 
 
 
Partenaires

Hébergement Web