Précédent   Forum des professionnels en informatique > PHP > Outils > Zend > Zend Framework > MVC
MVC Forum de support sur le développement d'applications de type modèle-vue-contrôleur avec Zend Framework ainsi que vos questions sur les plugins, les helpers etc. Avant de poster -> Cours MVC, FAQ ZF Controller
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 25/01/2008, 13h43   #1
Membre habitué
 
Inscription : septembre 2007
Messages : 357
Détails du profil
Informations forums :
Inscription : septembre 2007
Messages : 357
Points : 118
Points : 118
Par défaut Renvoyer vers une page si une action ou controlleur n'existe pas

Bonjour,

Lorsque je tappe une url qui n'existe pas (ex: monsite/controlleur/nimportequoi) Zend me génère une exception de ce type :

Code :
Fatal error: Uncaught exception 'Zend_Controller_Action_Exception' with message 'IndexController::errdsqfAction() does not exist and was not trapped in __call()' in C:\wamp\www\mytranspole\library\zend\Controller\Action.php:480 Stack trace: #0 [internal function]: Zend_Controller_Action->__call('errdsqfAction', Array) #1 C:\wamp\www\mytranspole\library\zend\Controller\Action.php(497): IndexController->errdsqfAction() #2 C:\wamp\www\mytranspole\library\zend\Controller\Dispatcher\Standard.php(238): Zend_Controller_Action->dispatch('errdsqfAction') #3 C:\wamp\www\mytranspole\library\zend\Controller\Front.php(920): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #4 C:\wamp\www\mytranspole\index.php(43): Zend_Controller_Front->dispatch() #5 {main} thrown in C:\wamp\www\mytranspole\library\zend\Controller\Action.php on line 480
Si dans mon fichier index.php, je remplace
Code :
$frontController->throwExceptions(true);
par
Code :
$frontController->throwExceptions(false);
j'obtiens
Code :
Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in C:\wamp\www\mytranspole\library\zend\Controller\Dispatcher\Standard.php:194 Stack trace: #0 C:\wamp\www\mytranspole\library\zend\Controller\Front.php(920): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 C:\wamp\www\mytranspole\index.php(43): Zend_Controller_Front->dispatch() #2 {main} thrown in C:\wamp\www\mytranspole\library\zend\Controller\Dispatcher\Standard.php on line 194
1. La ligne : "$frontController->throwExceptions(false);" n'est pas censé ne plus afficher d'exceptions ? Apparement non, mais comment faire pour ne plus les avoir ?

2. Je souhaiterai que lorsque le controlleur ou l'action n'existe pas, j'ai une redirection vers une page type "erreur 404 page non trouvé" ou bien vers la page principal du site. C'est possible ?

3. Ou est indiqué dans le fichier principal index.php que le fichier index à ouvrir par défaut est bien /monsite/Index ? Je suis mon premier tutorial (qui fonctionne) mais je ne vois pas ou est indiquer que par défaut il faut ouvrir index/ comme Controlleur. Est-il possible d'indiquer un autre Controlleur par défaut en guise de page d'accueil ? Voici le code que je pense être chargé d'afficher le controlleur par défaut index :
Code :
1
2
3
4
5
6
7
// setup controller
$frontController = Zend_Controller_Front::getInstance();
$frontController->throwExceptions(true);		//-- Contrôleur primaire lance les exceptions 
$frontController->setControllerDirectory('./application/controllers');		//-- Répertoires ou se trouvent le controlleur
 
// run!
$frontController->dispatch();
Ca fait plein de question, excusez moi, mais je suis vraiment vraiment débutant zend. merci
whitespirit est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/01/2008, 17h19   #2
Nouveau Membre du Club
 
Inscription : mars 2003
Messages : 31
Détails du profil
Informations personnelles :
Localisation : France, Haute Vienne (Limousin)

Informations forums :
Inscription : mars 2003
Messages : 31
Points : 26
Points : 26
Je me pose aussi la même question et je crois avoir trouvé un début de réponse...

Il faut créer un controlleur nommé "ErrorController" avec dedant la méthode "errorAction" et virer la ligne $front->throwExceptions(). Normalement les erreurs seront redirigées vers errorAction()...
ALkyD est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 07h19.


 
 
 
 
Partenaires

Hébergement Web