Bonjour,
J'ai un petit problème avec Zend je n'arrive pas à accéder à mes Modele car dans mon application.
Je ne sais pas comment débugguer pour voir où Zend va chercher mes models. j'ai une application pour module mais avec le même répertoire pour mes modele.
Bootstrap.php :
Bootstrappda.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206 <?php #coding: utf-8 // Step 1: APPLICATION CONSTANTS - Set the constants to use in this application. // These constants are accessible throughout the application, even in ini // files. We optionally set APPLICATION_PATH here in case our entry point // isn't index.php (e.g., if required from our test suite or a script). require_once 'constant.inc.php'; /** * bootstrap ancêtre * @todo à partir de ZF 1.10, faire hériter de Zend_Application_Bootstrap_Bootstrap * @package exposehome * @subpackage kernel * @category bootstrap * @author ECAROT * */ abstract class Bootstrap { /** * @var Zend_Controller_Front */ protected static $_frontController = null; /** * @var Zend_Registry */ protected static $_registry = null; /** * mise en place d'un système de cache * @access private */ protected static function _setupCache() { /* if (! is_dir(GRC_TEMP_DIR)) { mkdir(GRC_TEMP_DIR); } self::$_registry->set('cache', $cache);*/ } /** * Set up autoloading */ static protected function _autoload() { require_once 'Zend/Loader/Autoloader.php'; $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->setFallbackAutoloader(true); //Configure l'autoload pour inclure le module portail_citoyen et le module portail_accueil new Zend_Application_Module_Autoloader( array( 'namespace' => 'Portaildta_', 'basePath' => dirname(__FILE__) . '/modules/portaildta', 'resourceTypes' => array( 'library' => array( 'path' => 'library/', 'namespace' => 'Library' ), 'models' => array( 'path' => 'models/', 'namespace' => 'Model' /* sans 's' */ ) ) ) ); } /** * @param string $config_file_path * @param string $section * @access private * @return Zend_Config_Ini */ protected static function _setupConfig($configFilePath, $section) { // CONFIGURATION - Setup the configuration object // The Zend_Config_Ini component will parse the ini file, and resolve all of // the values for the given section. Here we will be using the section name // that corresponds to the APP's Environment return new Zend_Config_Ini($configFilePath, $section); } /** * */ /*protected static function _setupDatabase() { $db = Zend_Db::factory(Zend_Registry::get('configuration')->database); Zend_Db_Table::setDefaultAdapter($db); //$db = Zend_Db::factory($configuration->database); //Zend_Db_Table_Abstract::setDefaultAdapter($db); //self::$_registry->set('dbAdapter', $db); } */ /** * mise en place de la "ZFDebug toolbar" */ protected static function _setupDebug() { // seulement si on est en mode "development" if (APPLICATION_ENV != 'development') { return; } // et seulement si on n'est pas sous IE // (car message d'erreur javascript si on est sous IE) $req = new Zend_Controller_Request_Http(); $ua = $req->getServer('HTTP_USER_AGENT'); unset($req); // NB : possible d'utiliser $browser = get_browser(null, true); mais nécessite un browscap.ini if ((strpos($ua, 'Chrome') === false) and (strpos($ua, 'Firefox') === false) and (strpos($ua, 'Opera') === false)) { return; } // toutes les conditions sont réunies, mise en place de la toolbar $options = array( 'jquery_path' => '/js/jquery.js', 'plugins' => array( 'Variables', 'Html', /*'Database' => array('adapter' => array('standard' => $db)),*/ 'File' => array('basePath' => APPLICATION_PATH), 'Memory', 'Time', 'Registry', /*'Cache' => array('backend' => $cache->getBackend()), */ 'Exception' ) ); $debugBar = new ZFDebug_Controller_Plugin_Debug($options); self::$_frontController->registerPlugin($debugBar); } /** * démarrage du MVC * @param $configuration Zend_Config_Ini * @access private */ protected static function _setupLayout($configuration) { //$layout_path['pluginClass'] = 'WinWinweb_Layout_Controller_Plugin_Layout'; Zend_Layout::startMvc($configuration); } /** * définit le système de log * @param string $file */ protected static function _setupLogger($file) { $logger = new Zend_Log(); // pour déraciner le log (écrire nulle part): //$logger->addWriter(new Zend_Log_Writer_Null()); //$logger->addWriter(new Zend_Log_Writer_Firebug()); $logger->addWriter(new Zend_Log_Writer_Stream($file)); // choix du niveau de debuggage $logLevel = intval(Zend_Registry::get('configuration')->logLevel); $logger->addFilter(new Zend_Log_Filter_Priority($logLevel)); /* EMERG 0 : Urgence : le système est inutilisable ALERT 1 : Alerte: une mesure corrective doit être prise immédiatement CRIT 2 : Critique : états critiques ERR 3 : Erreur: états d'erreur WARN 4 : Avertissement: états d'avertissement NOTICE 5 : Notice: normal mais état significatif INFO 6 : Information: messages d'informations DEBUG 7 : Debug: messages de déboguages */ //$log->setEventItem('Memory used', memory_get_usage()); self::$_registry->set('logger', $logger); unset($logger); } /** * mise en place de l'environnement nécessaire à l'exécution * @access private */ protected static function _setupRegistry() { self::$_registry = Zend_Registry::getInstance(); } /** * mise en place des routes * @access private */ protected static function _setupRoute() { /* @var $router Zend_Controller_Router_Rewrite */ $router = self::$_frontController->getRouter(); } }
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
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 <?php #coding: utf-8 require_once APPLICATION_PATH . '/Bootstrap.php'; /** * * @package portailDTA * @subpackage kernel * @category bootstrap * @author ECAROT * */ class bootstrapPortaildta extends Bootstrap { static public function run() { //self::setupEnvironment(); self::_prepare(); try { // mettre cette ligne pour que ErrorController fasse son job // si cette ligne est commentée, c'est le catch ci-dessous qui sera fait self::$_frontController->throwExceptions(false); // Dispatch the request using the front controller. // The front controller is a singleton, and should be setup by now. We // will grab an instance and call dispatch() on it, which dispatches the // current request. self::$_frontController->dispatch(); } catch(Exception $exception) { echo $exception->getMessage(); echo "<html><body><center>" . "Une exeption a été soulevé par le bootstrap de l'application."; if (defined('APPLICATION_ENV') && APPLICATION_ENV != 'production' ) { echo "<br /><br />" . $exception->getMessage() . "<br />" . "<div align='left'>Trace pile d'execution:" . "<pre>" . $exception->getTraceAsString() . "</pre></div>"; } echo '</center></body></html>'; exit(1); } } /** * minimum syndical pour lancer des tests unitaires sur des objets de l'application */ static public function runForUnitTests() { self::_prepare(); } /** * */ protected static function _prepare() { parent::_autoload(); //Config du registry parent::_setupRegistry(); //Config du fichier de config :) /* @var $config Zend_Config_Ini */ $iniConfig = parent::_setupConfig(APPLICATION_PATH . '/config/config.ini', APPLICATION_ENV); parent::$_registry->set('configuration', $iniConfig); //Mise en place du controller principal self::_setupFrontController( array( //'default' => APPLICATION_PATH . '/modules/portailexposehome/controllers', 'portaildta' => APPLICATION_PATH . '/modules/portaildta/controllers' ) ); //Mise en place des routes parent::_setupRoute(); //Mise en place du layout /* @var $config Zend_Config_Ini */ $config = new Zend_Config_Ini(APPLICATION_PATH . '/config/config.ini', 'layoutPortailDta'); parent::_setupLayout($config); unset($config); parent::_setupDebug(); } /** * * @param unknown_type $controllersPath */ protected static function _setupFrontController($controllersPath) { // FRONT CONTROLLER - Get the front controller. // The Zend_Front_Controller class implements the Singleton pattern, which is a // design pattern used to ensure there is only one instance of // Zend_Front_Controller created on each request. self::$_frontController = Zend_Controller_Front::getInstance(); //self::$_frontController->setRequest(new Zend_Controller_Request_Http()); self::$_frontController->throwExceptions(true); //self::$_frontController->returnResponse(true); // CONTROLLER DIRECTORY SETUP - Point the front controller to your action // controller directory. self::$_frontController->setControllerDirectory($controllersPath); self::$_frontController->setDefaultModule('portaildta'); self::$_frontController->setDefaultControllerName('index'); self::$_frontController->setDefaultAction('test'); //self::$_frontController->setParam('registry', self::$_registry); self::$_frontController->setParam('context', 'portaildta'); // APPLICATION ENVIRONMENT - Set the current environment. self::$_frontController->setParam('env', APPLICATION_ENV); } }
Personne.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 /** * loader de l'appli dta * * * @package dta * @subpackage kernel */ define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application/')); set_include_path( realpath(APPLICATION_PATH . '/../library') . PATH_SEPARATOR . realpath(APPLICATION_PATH . '/models') . PATH_SEPARATOR . get_include_path() ); // Define application environment // voir le virtual host, pour mettre par exemple : // SetEnv APPLICATION_ENV development // s'il n'y en a pas, alors la ligne ci-dessous sera prise en compte defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); require_once APPLICATION_PATH . '/Bootstrapdta.php'; bootstrapPortaildta::run();
IndexController.php :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 <?php class Model_Personne extends Zend_Db_Table { protected $_name = 'PERSONNE'; private function getPersonnesAll() { return $this->fetchAll()->toArray(); } private function getPersonneNom($name = '') { return $this->fetchAll()->toArray(array('nom_personne = ?'=> $name)); } }
J'obtiens :
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 <?php class IndexController extends Zend_Controller_Action { public function init() { $this->view->headTitle('Socialisme Citoyen'); } public function testAction() { /*$loader = Zend_Loader_Autoloader::getInstance(); die( print_r( $loader->getAutoloaders() ));*/ $model = new Model_Personne(); $this->view->test = "ESSAI 1"; } }
Fatal error: Class 'Model_Personne' not found in /var/www/DTA/application/modules/portaildta/controllers/IndexController.php on line 12
Je ne sais pas pourquoi il ne veut pas aller les chercher au bon endroit...
Et lorsque j'affiche mes path comme ceci :
J'obtiens :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 $loader = Zend_Loader_Autoloader::getInstance(); die( print_r( $loader->getAutoloaders() ));
Mais il ne veut toujours pas et je ne comprend pas pourquoi il définit plusieurs "Portaildta_Model" dans getAutoloaders().
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 Array ( [0] => Zend_Application_Module_Autoloader Object ( [_basePath:protected] => /var/www/DTA/application/modules/portaildta [_components:protected] => Array ( [Portaildta_Library] => /var/www/DTA/application/modules/portaildta/library [Portaildta_Model] => /var/www/DTA/application/modules/portaildta/models [Portaildta_Model_DbTable] => /var/www/DTA/application/modules/portaildta/models/DbTable [Portaildta_Model_Mapper] => /var/www/DTA/application/modules/portaildta/models/mappers [Portaildta_Form] => /var/www/DTA/application/modules/portaildta/forms [Portaildta_Plugin] => /var/www/DTA/application/modules/portaildta/plugins [Portaildta_Service] => /var/www/DTA/application/modules/portaildta/services [Portaildta_View_Helper] => /var/www/DTA/application/modules/portaildta/views/helpers [Portaildta_View_Filter] => /var/www/DTA/application/modules/portaildta/views/filters ) [_defaultResourceType:protected] => model [_namespace:protected] => Portaildta [_resourceTypes:protected] => Array ( [library] => Array ( [namespace] => Portaildta_Library [path] => /var/www/DTA/application/modules/portaildta/library ) [models] => Array ( [namespace] => Portaildta_Model [path] => /var/www/DTA/application/modules/portaildta//var/www/DTA/application/models ) [dbtable] => Array ( [namespace] => Portaildta_Model_DbTable [path] => /var/www/DTA/application/modules/portaildta/models/DbTable ) [mappers] => Array ( [namespace] => Portaildta_Model_Mapper [path] => /var/www/DTA/application/modules/portaildta/models/mappers ) [form] => Array ( [namespace] => Portaildta_Form [path] => /var/www/DTA/application/modules/portaildta/forms ) [model] => Array ( [namespace] => Portaildta_Model [path] => /var/www/DTA/application/modules/portaildta/models ) [plugin] => Array ( [namespace] => Portaildta_Plugin [path] => /var/www/DTA/application/modules/portaildta/plugins ) [service] => Array ( [namespace] => Portaildta_Service [path] => /var/www/DTA/application/modules/portaildta/services ) [viewhelper] => Array ( [namespace] => Portaildta_View_Helper [path] => /var/www/DTA/application/modules/portaildta/views/helpers ) [viewfilter] => Array ( [namespace] => Portaildta_View_Filter [path] => /var/www/DTA/application/modules/portaildta/views/filters ) ) ) )
Pour vous aidezà m'aider un peu plus voiçi mon arborescence :
Voilà j'ai un dossier models/ commun à tout mes modules. Mes modèles ont ce nom par exemple: Model_Personne
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+application ++config ++languages ++layouts ++models ++-Personne.php ++modules +++portaildta ++++controllers ++++forms ++++views +library +public
J’appelle alors mon modèle Personne.php dans mon dossier models. Je ne comprend pas pourquoi cela ne fonctionne pas
Merci d'avance
Partager