Bonjour,
Je rencontre sur un problème depuis quelques temps. Après l'avoir "repoussé", avoir cherché, je l'expose.
=>Brièvement : j'ai 2 modules (site et admin), je n'arrive pas à accéder aux contrôleurs du module admin (sans doute à cause de mes routes).
=>En detail :
j'ai donc deux modules : site et admin. "site" étant pour le front office et "admin" pour l'administration. Mes controleurs sont dans /application/[moduleX]/controllers/ (et les vues dans /application/[moduleX]/views/script/[controllerY]/[fichier.tpl] => le tpl est paramètre ok)
J'accède au différentes URL grace à des routes configurées. Elles fonctionnent bien pour le site, là où j'ai eu un problème, ça a été pour l'admin.
J'ai donc ajouté cette route là :
Elle semblait bien fonctionner (un appelle à http://localhost/admin/ chargait l'action index du controller index du module admin), mais j'ai voulu appeler http://localhost/admin/actualite/ajouter, et là c'est le drame, c'est le index/index qui est chargé !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 $route = new Zend_Controller_Router_Route( 'admin/*', array('module' => 'admin')); $router->addRoute('admin', $route);
J'ai modifié la route en
La conséquence est que je ne peux plus accéder aux contrôleurs du module admin. Le message d'erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 $route = new Zend_Controller_Router_Route( 'admin/:controller/:action/*', array('module' => 'admin')); $router->addRoute('admin', $route);
Code x : 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291 Page introuvable retour DEBUG INFOS : Exception de type Zend_Controller_Dispatcher_Exception Invalid controller specified (actualite) envoy�e dans /Users/nicolas/SUPINFO/stage_XXXX/XXXX/site/application/lib/Zend/Controller/Dispatcher/Standard.php � la ligne 249 Stack Trace : object(Zend_Controller_Dispatcher_Exception)#32 (6) { ["message:protected"] => string(40) "Invalid controller specified (actualite)" ["string:private"] => string(0) "" ["code:protected"] => int(0) ["file:protected"] => string(104) "/Users/nicolas/SUPINFO/stage_XXXX/XXXX/site/application/lib/Zend/Controller/Dispatcher/Standard.php" ["line:protected"] => int(249) ["trace:private"] => array(2) { [0] => array(6) { ["file"] => string(90) "/Users/nicolas/SUPINFO/stage_XXX/XXX/site/application/lib/Zend/Controller/Front.php" ["line"] => int(914) ["function"] => string(8) "dispatch" ["class"] => string(35) "Zend_Controller_Dispatcher_Standard" ["type"] => string(2) "->" ["args"] => array(2) { [0] => object(Zend_Controller_Request_Http)#30 (14) { ["_paramSources:protected"] => array(2) { [0] => string(4) "_GET" [1] => string(5) "_POST" } ["_requestUri:protected"] => string(24) "/admin/actualite/ajouter" ["_baseUrl:protected"] => string(0) "" ["_basePath:protected"] => NULL ["_pathInfo:protected"] => string(24) "/admin/actualite/ajouter" ["_params:protected"] => array(4) { ["controller"] => string(9) "actualite" ["action"] => string(7) "ajouter" ["module"] => string(5) "admin" ["error_handler"] => object(ArrayObject)#33 (3) { ["exception"] => object(Zend_Controller_Dispatcher_Exception)#32 (6) { ["message:protected"] => string(40) "Invalid controller specified (actualite)" ["string:private"] => string(0) "" ["code:protected"] => int(0) ["file:protected"] => string(104) "/Users/nicolas/SUPINFO/stage_XXXX/XXXX/site/application/lib/Zend/Controller/Dispatcher/Standard.php" ["line:protected"] => int(249) ["trace:private"] => array(2) { [0] => array(6) { ["file"] => string(90) "/Users/nicolas/SUPINFO/stage_XXX/XXX/site/application/lib/Zend/Controller/Front.php" ["line"] => int(914) ["function"] => string(8) "dispatch" ["class"] => string(35) "Zend_Controller_Dispatcher_Standard" ["type"] => string(2) "->" ["args"] => array(2) { [0] => object(Zend_Controller_Request_Http)#30 (14) { ["_paramSources:protected"] => array(2) { [0] => string(4) "_GET" [1] => string(5) "_POST" } ["_requestUri:protected"] => string(24) "/admin/actualite/ajouter" ["_baseUrl:protected"] => string(0) "" ["_basePath:protected"] => NULL ["_pathInfo:protected"] => string(24) "/admin/actualite/ajouter" ["_params:protected"] => array(4) { ["controller"] => string(9) "actualite" ["action"] => string(7) "ajouter" ["module"] => string(5) "admin" ["error_handler"] => object(ArrayObject)#33 (3) { ["exception"] => *RECURSION* ["type"] => string(23) "EXCEPTION_NO_CONTROLLER" ["request"] => object(Zend_Controller_Request_Http)#34 (14) { ["_paramSources:protected"] => array(2) { [0] => string(4) "_GET" [1] => string(5) "_POST" } ["_requestUri:protected"] => string(24) "/admin/actualite/ajouter" ["_baseUrl:protected"] => string(0) "" ["_basePath:protected"] => NULL ["_pathInfo:protected"] => string(24) "/admin/actualite/ajouter" ["_params:protected"] => array(3) { ["controller"] => string(9) "actualite" ["action"] => string(7) "ajouter" ["module"] => string(5) "admin" } ["_aliases:protected"] => array(0) { } ["_dispatched:protected"] => bool(true) ["_module:protected"] => string(5) "admin" ["_moduleKey:protected"] => string(6) "module" ["_controller:protected"] => string(9) "actualite" ["_controllerKey:protected"] => string(10) "controller" ["_action:protected"] => string(7) "ajouter" ["_actionKey:protected"] => string(6) "action" } } } ["_aliases:protected"] => array(0) { } ["_dispatched:protected"] => bool(true) ["_module:protected"] => string(7) "default" ["_moduleKey:protected"] => string(6) "module" ["_controller:protected"] => string(5) "error" ["_controllerKey:protected"] => string(10) "controller" ["_action:protected"] => string(5) "error" ["_actionKey:protected"] => string(6) "action" } [1] => object(Zend_Controller_Response_Http)#31 (8) { ["_body:protected"] => array(1) { ["error"] => string(69) "<p>Page introuvable</p><a href="javascript:history.back()">retour</a>" } ["_exceptions:protected"] => array(1) { [0] => *RECURSION* } ["_headers:protected"] => array(0) { } ["_headersRaw:protected"] => array(0) { } ["_httpResponseCode:protected"] => int(404) ["_isRedirect:protected"] => bool(false) ["_renderExceptions:protected"] => bool(false) ["headersSentThrowsException"] => bool(true) } } } [1] => array(6) { ["file"] => string(65) "/Users/nicolas/SUPINFO/stage_XXXX/XXXX/site/htdocs/index.php" ["line"] => int(173) ["function"] => string(8) "dispatch" ["class"] => string(21) "Zend_Controller_Front" ["type"] => string(2) "->" ["args"] => array(0) { } } } } ["type"] => string(23) "EXCEPTION_NO_CONTROLLER" ["request"] => object(Zend_Controller_Request_Http)#34 (14) { ["_paramSources:protected"] => array(2) { [0] => string(4) "_GET" [1] => string(5) "_POST" } ["_requestUri:protected"] => string(24) "/admin/actualite/ajouter" ["_baseUrl:protected"] => string(0) "" ["_basePath:protected"] => NULL ["_pathInfo:protected"] => string(24) "/admin/actualite/ajouter" ["_params:protected"] => array(3) { ["controller"] => string(9) "actualite" ["action"] => string(7) "ajouter" ["module"] => string(5) "admin" } ["_aliases:protected"] => array(0) { } ["_dispatched:protected"] => bool(true) ["_module:protected"] => string(5) "admin" ["_moduleKey:protected"] => string(6) "module" ["_controller:protected"] => string(9) "actualite" ["_controllerKey:protected"] => string(10) "controller" ["_action:protected"] => string(7) "ajouter" ["_actionKey:protected"] => string(6) "action" } } } ["_aliases:protected"] => array(0) { } ["_dispatched:protected"] => bool(true) ["_module:protected"] => string(7) "default" ["_moduleKey:protected"] => string(6) "module" ["_controller:protected"] => string(5) "error" ["_controllerKey:protected"] => string(10) "controller" ["_action:protected"] => string(5) "error" ["_actionKey:protected"] => string(6) "action" } [1] => object(Zend_Controller_Response_Http)#31 (8) { ["_body:protected"] => array(1) { ["error"] => string(69) "<p>Page introuvable</p><a href="javascript:history.back()">retour</a>" } ["_exceptions:protected"] => array(1) { [0] => object(Zend_Controller_Dispatcher_Exception)#32 (6) { ["message:protected"] => string(40) "Invalid controller specified (actualite)" ["string:private"] => string(0) "" ["code:protected"] => int(0) ["file:protected"] => string(104) "/Users/nicolas/SUPINFO/stage_XXX/XXX/site/application/lib/Zend/Controller/Dispatcher/Standard.php" ["line:protected"] => int(249) ["trace:private"] => array(2) { [0] => array(6) { ["file"] => string(90) "/Users/nicolas/SUPINFO/stage_XXX/XXXX/site/application/lib/Zend/Controller/Front.php" ["line"] => int(914) ["function"] => string(8) "dispatch" ["class"] => string(35) "Zend_Controller_Dispatcher_Standard" ["type"] => string(2) "->" ["args"] => array(2) { [0] => object(Zend_Controller_Request_Http)#30 (14) { ["_paramSources:protected"] => array(2) { [0] => string(4) "_GET" [1] => string(5) "_POST" } ["_requestUri:protected"] => string(24) "/admin/actualite/ajouter" ["_baseUrl:protected"] => string(0) "" ["_basePath:protected"] => NULL ["_pathInfo:protected"] => string(24) "/admin/actualite/ajouter" ["_params:protected"] => array(4) { ["controller"] => string(9) "actualite" ["action"] => string(7) "ajouter" ["module"] => string(5) "admin" ["error_handler"] => object(ArrayObject)#33 (3) { ["exception"] => *RECURSION* ["type"] => string(23) "EXCEPTION_NO_CONTROLLER" ["request"] => object(Zend_Controller_Request_Http)#34 (14) { ["_paramSources:protected"] => array(2) { [0] => string(4) "_GET" [1] => string(5) "_POST" } ["_requestUri:protected"] => string(24) "/admin/actualite/ajouter" ["_baseUrl:protected"] => string(0) "" ["_basePath:protected"] => NULL ["_pathInfo:protected"] => string(24) "/admin/actualite/ajouter" ["_params:protected"] => array(3) { ["controller"] => string(9) "actualite" ["action"] => string(7) "ajouter" ["module"] => string(5) "admin" } ["_aliases:protected"] => array(0) { } ["_dispatched:protected"] => bool(true) ["_module:protected"] => string(5) "admin" ["_moduleKey:protected"] => string(6) "module" ["_controller:protected"] => string(9) "actualite" ["_controllerKey:protected"] => string(10) "controller" ["_action:protected"] => string(7) "ajouter" ["_actionKey:protected"] => string(6) "action" } } } ["_aliases:protected"] => array(0) { } ["_dispatched:protected"] => bool(true) ["_module:protected"] => string(7) "default" ["_moduleKey:protected"] => string(6) "module" ["_controller:protected"] => string(5) "error" ["_controllerKey:protected"] => string(10) "controller" ["_action:protected"] => string(5) "error" ["_actionKey:protected"] => string(6) "action" } [1] => object(Zend_Controller_Response_Http)#31 (8) { ["_body:protected"] => array(1) { ["error"] => string(69) "<p>Page introuvable</p><a href="javascript:history.back()">retour</a>" } ["_exceptions:protected"] => array(1) { [0] => *RECURSION* } ["_headers:protected"] => array(0) { } ["_headersRaw:protected"] => array(0) { } ["_httpResponseCode:protected"] => int(404) ["_isRedirect:protected"] => bool(false) ["_renderExceptions:protected"] => bool(false) ["headersSentThrowsException"] => bool(true) } } } [1] => array(6) { ["file"] => string(65) "/Users/nicolas/SUPINFO/stage_XXX/XXXX/site/htdocs/index.php" ["line"] => int(173) ["function"] => string(8) "dispatch" ["class"] => string(21) "Zend_Controller_Front" ["type"] => string(2) "->" ["args"] => array(0) { } } } } } ["_headers:protected"] => array(0) { } ["_headersRaw:protected"] => array(0) { } ["_httpResponseCode:protected"] => int(404) ["_isRedirect:protected"] => bool(false) ["_renderExceptions:protected"] => bool(false) ["headersSentThrowsException"] => bool(true) } } } [1] => array(6) { ["file"] => string(65) "/Users/nicolas/SUPINFO/stage_XXX/XXX/site/htdocs/index.php" ["line"] => int(173) ["function"] => string(8) "dispatch" ["class"] => string(21) "Zend_Controller_Front" ["type"] => string(2) "->" ["args"] => array(0) { } } } }
Voila mon fichier index.php (le bootstrap je crois):
Merci d'avance de votre aide.
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 <? error_reporting(E_ALL|E_STRICT); date_default_timezone_set('Europe/Paris'); ini_set('include_path', '.' . PATH_SEPARATOR . '../application/lib' . PATH_SEPARATOR . '../application/modules/site/models/' . PATH_SEPARATOR . '../application/modules/admin/models/' . PATH_SEPARATOR . ini_get('include_path') ); include "Zend/Loader.php"; Zend_Loader::loadClass('Zend_Cache'); Zend_Loader::loadClass('Zend_Db_Table_Abstract'); Zend_Loader::loadClass('Zend_Registry'); Zend_Loader::loadClass('Zend_Log'); Zend_Loader::loadClass('Zend_Log_Writer_Stream'); $writer = new Zend_Log_Writer_Stream('../application/log/fichier_log.log'); $logger = new Zend_Log($writer); Zend_Registry::set('logger',$logger); //Zend_Log::registerLogger(new Zend_Log_Writer_Stream('../application/log/fichier_log.log')); //Zend_Log::setMessagePrefix('['. date('Y-m-d G:i') . '] ' . $_SERVER['REMOTE_ADDR'] . ': '); /* //INITIALISAION DU CACHE //A METTRE EN PRODUCTION $logger->log("Debut creation du cache", Zend_Log::DEBUG); $cache_bdd = Zend_Cache::factory('Core', 'File', array('lifetime'=>7200), array('cache_dir' => '../application/var/cache/')); Zend_Db_Table_Abstract::setDefaultMetadataCache($cache_bdd); $frontendOptions = array( 'lifetime' => 7200, 'debug_header' => true, // for debugging 'regexps' => array( '^/$' => array('cache' => true), '^/contact' => array('cache' => true), '^/credits' => array('cache' => true), '^/aide' => array('cache' => true), '^/droit' => array('cache' => true), /*'^/article/' => array('cache' => false), // we don't cache the ArticleController... '^/article/view/' => array( // ...but we cache the "view" action of 'cache' => true, // this ArticleController 'cache_with_post_variables' => true, // and we cache even there are some variables in $_POST 'make_id_with_post_variables' => true, // (but the cache will be dependent of the $_POST array) )/ ) ); $backendOptions = array( 'cache_dir' => '../application/var/cache/' ); $cache = Zend_Cache::factory('Page', 'File', $frontendOptions, $backendOptions); $logger->log("Fin creation du cache", Zend_Log::DEBUG); $logger->log("Demarrage du cache", Zend_Log::DEBUG); $cache->start(); */ Zend_Loader::loadClass('Zend_Auth'); Zend_Loader::loadClass('Zend_Config_Ini'); Zend_Loader::loadClass('Zend_Controller_Front'); Zend_Loader::loadClass('Zend_Controller_Router_Rewrite'); Zend_Loader::loadClass('Zend_Controller_Router_Route'); Zend_Loader::loadClass('Zend_Controller_Router_Route_Regex'); Zend_Loader::loadClass('Zend_Controller_Router_Route_Module'); Zend_Loader::loadClass('Zend_Controller_Router_Route_Static'); Zend_Loader::loadClass('Zend_Db'); Zend_Loader::loadClass('Zend_Db_Table_Row_Abstract'); Zend_Loader::loadClass('Zend_Debug'); Zend_Loader::loadClass('Zend_View'); Zend_Loader::loadClass('Membre'); Zend_Loader::loadClass('Membres'); Zend_Loader::loadClass('MembresEvenements'); Zend_Loader::loadClass('Evenement'); Zend_Loader::loadClass('Evenements'); Zend_Loader::loadClass('Document'); Zend_Loader::loadClass('Documents'); Zend_Loader::loadClass('DocumentsEvenements'); //Zend_Loader::loadClass('Groupe'); ///Zend_Loader::loadClass('Groupes'); //Zend_Loader::loadClass('MembresGroupes'); $logger->log("Chargement de la configuration", Zend_Log::DEBUG); $config = new Zend_Config_Ini('../application/config/config.ini', 'dev_local'); $logger->log("Initialisation de la BDD", Zend_Log::DEBUG); $db = Zend_Db::factory($config->database->adapter, $config->database->params->toArray()); Zend_Db_Table_Abstract::setDefaultAdapter($db); Zend_Registry::set('db',$db); $front = Zend_Controller_Front::getInstance(); // Set several module directories at once: $front->setControllerDirectory(array( 'admin' => '../application/modules/admin/controllers', 'default' => '../application/modules/site/controllers' )); $router = $front->getRouter(); // returns a rewrite router by default $router->addRoute('default', new Zend_Controller_Router_Route_Module(array('controller' => 'site', 'action' => 'index')) ); //route pour le profil d'un membre. URL de la forme 'membre/' suivi du login du membre $route = new Zend_Controller_Router_Route( 'admin/:controller/:action/*', array('module' => 'admin')); $router->addRoute('admin', $route); //route dynamique pour les evenements $route = new Zend_Controller_Router_Route( 'evenement/:id', array('controller' => 'evenement', 'action' => 'detail'), array('id' => '\d+')); $router->addRoute('detailEvenement', $route); //route pour le profil d'un membre. URL de la forme 'membre/' suivi du login du membre //$route = new Zend_Controller_Router_Route( 'membre/:nom', array('controller' => 'membre', 'action' => 'profil')); //$router->addRoute('profilMembre', $route); $route = new Zend_Controller_Router_Route( 'membre/:id', array('controller' => 'membre', 'action' => 'profil'), array('id'=>'\d+')); $router->addRoute('profilMembre', $route); //route dynamique pour l'interface de gestion $route = new Zend_Controller_Router_Route('gestion/*', array('controller' => 'membre', 'action' => 'gestion')); $router->addRoute('gestion', $route); //route statique pour le formulaire de connexion $route = new Zend_Controller_Router_Route_Static('connexion', array('controller' => 'auth', 'action' => 'login')); $router->addRoute('connexion', $route); //route statique pour la deconnexion $route = new Zend_Controller_Router_Route_Static('deconnexion', array('controller' => 'auth', 'action' => 'logout')); $router->addRoute('deconnexion', $route); //route statique pour le formulaire d'enregistrement $route = new Zend_Controller_Router_Route_Static('inscription', array('controller' => 'auth', 'action' => 'register')); $router->addRoute('inscription', $route); //route statique pour le formulaire de contact $route = new Zend_Controller_Router_Route_Static('contact', array('controller' => 'site', 'action' => 'contact')); $router->addRoute('contact', $route); //route statique pour les credis $route = new Zend_Controller_Router_Route_Static('credits', array('controller' => 'site', 'action' => 'credits')); $router->addRoute('credits', $route); //route statique pour la page d'aide $route = new Zend_Controller_Router_Route_Static('aide', array('controller' => 'site', 'action' => 'help')); $router->addRoute('aide', $route); //route statique pour la page d'accueil $route = new Zend_Controller_Router_Route_Static('accueil', array('controller' => 'site', 'action' => 'index')); $router->addRoute('accueil', $route); //route statique pour la page legal $route = new Zend_Controller_Router_Route_Static('droit', array('controller' => 'site', 'action' => 'legals')); $router->addRoute('droit', $route); //route statique pour le formulaire de redaction //$router->addRoute('annonce/rediger', new Zend_Controller_Router_Route_Static( 'annonce/rediger', array('controller' => 'annonce', 'action' => 'new')) ); $logger->log("Route cree", Zend_Log::DEBUG); define('ROOT_URL', 'http://XXXX/'); $view = new Zend_View(); $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); $viewRenderer->setView($view)->setViewSuffix('tpl'); $logger->log("Dispatching", Zend_Log::DEBUG); $front->dispatch();
Partager