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

MVC PHP Discussion :

domain.com/profil/index/id/765/ -> domain.com/profil/id/765/ ?


Sujet :

MVC PHP

  1. #1
    Membre averti
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2008
    Messages
    519
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Janvier 2008
    Messages : 519
    Points : 311
    Points
    311
    Par défaut domain.com/profil/index/id/765/ -> domain.com/profil/id/765/ ?
    Bonjour,

    Pour pouvoir envoyer des paramètres à la méthode index du contrôleur profil je suis obligé de mettre index dans mon url.

    Est-il possible d'avoir un résultat équivalent avec l'url domain.com/profil/id/765/ ?

    Merci

  2. #2
    En attente de confirmation mail

    Homme Profil pro
    Développeur Web
    Inscrit en
    Février 2003
    Messages
    253
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Février 2003
    Messages : 253
    Points : 637
    Points
    637
    Par défaut
    Bonsoir,

    Il suffit de configurer une route pour ça, c'est un projet sous ZF 1 ou 2 ?

  3. #3
    Membre averti
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2008
    Messages
    519
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Janvier 2008
    Messages : 519
    Points : 311
    Points
    311
    Par défaut
    1.12

  4. #4
    En attente de confirmation mail

    Homme Profil pro
    Développeur Web
    Inscrit en
    Février 2003
    Messages
    253
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Février 2003
    Messages : 253
    Points : 637
    Points
    637
    Par défaut
    Je te conseille de voir par ici : http://framework.zend.com/manual/1.1...outes.standard

    Une route "standard" avec comme pattern profil/* et des valeurs par défaut pour le module, le contrôleur et l'action devraient répondre au besoin.

  5. #5
    Membre averti
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2008
    Messages
    519
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Janvier 2008
    Messages : 519
    Points : 311
    Points
    311
    Par défaut
    Salut,

    J'ai essayé de faire ma réécriture d'URL avec Zend_Controller_Router_Rewrite mais quelque chose semble bloquer :

    J'aimerai réécrire l'URL http://www.ndd.dev/interet/index/id/1/ pour http://www.ndd.dev/i/rouen/1/

    Pour cela j'ai ajouté dans mon bootstrap :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    protected function _initRouter () {
     
    	$front = $this->bootstrap('FrontController')->getResource('FrontController');
    	$config = new Zend_Config_Ini(APPLICATION_PATH.'/config/application.ini', APPLICATION_ENV);
    	$routing = new Zend_Controller_Router_Rewrite();
    	$routing->addConfig($config, 'routes');
    	$front->setRouter($routing);
     
    }
    et dans mon application.ini :

    [production]
    [...]
    routes.interet.type = "Zend_Controller_Router_Route_Regex"
    routes.interet.route = "/i/(.+)/([0-9]+)/"
    routes.interet.defaults.controller = "interet"
    routes.interet.defaults.action = "index"
    routes.interet.map.1 = "seo"
    routes.interet.map.2 = "id"
    routes.interet.reverse ="i/%s/%d/"
    Et mon .htaccess est le suivant :

    RewriteEngine On

    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php
    Mais j'obtiens le message d'erreur suivant :

    Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in /www/library/Zend/Controller/Dispatcher/Standard.php:248 Stack trace: #0 /www/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 /www/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch() #2 /www/htdocs/xxx/application/Bootstrap.php(8): Zend_Application_Bootstrap_Bootstrap->run() #3 /www/library/Zend/Application.php(366): Bootstrap->run() #4 /www/htdocs/xxx/html/index.php(15): Zend_Application->run() #5 {main} Next exception 'Zend_Controller_Exception' with message 'Invalid controller specified (error)#0 /www/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 /www/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller in /www/library/Zend/Controller/Plugin/Broker.php on line 336
    L'accès depuis http://www.ndd.dev/interet/index/id/1/ reste lui toujours disponible.

    Merci

  6. #6
    Membre averti Avatar de Njörd
    Homme Profil pro
    Inscrit en
    Janvier 2010
    Messages
    190
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2010
    Messages : 190
    Points : 390
    Points
    390
    Par défaut
    Bonjour Khleo,

    As-tu bien modifié tes liens pour faire appel à ta route ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    $this->url(array('module' => 'tonModule', 'controller' => 'tonController', 'action' => 'tonAction'), 'leNomDeTaRoute', true);

  7. #7
    Membre averti
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2008
    Messages
    519
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Janvier 2008
    Messages : 519
    Points : 311
    Points
    311
    Par défaut
    Salut,

    J'ai directement saisi mon URL http://www.ndd.dev/i/rouen/1/ dans mon navigateur.

    Mes liens sont en dures pour l'instant.

  8. #8
    Membre averti Avatar de Njörd
    Homme Profil pro
    Inscrit en
    Janvier 2010
    Messages
    190
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2010
    Messages : 190
    Points : 390
    Points
    390
    Par défaut
    Bonjour Khleo,

    A tout hasard si tu écris ta base dans le .htaccess peut-être ? (celle de ton alias apache ou vhost)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    RewriteEngine On
    
    RewriteBase /www.ndd.dev
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php

  9. #9
    Membre averti
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2008
    Messages
    519
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Janvier 2008
    Messages : 519
    Points : 311
    Points
    311
    Par défaut
    Salut,

    Non le fait de changer RewriteBase ne change rien.

    J'ai essayé d'ajouter ma réécriture d'url dans le .htaccess et j'obtiens le même message d'erreur.

    Options +FollowSymlinks

    RewriteEngine On

    RewriteRule ^i/(.+)/([0-9]+)/ interet/index/id/1/ [L]

    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php
    Peut-être que le problème provient du .htaccess

  10. #10
    Membre averti
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2008
    Messages
    519
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Janvier 2008
    Messages : 519
    Points : 311
    Points
    311
    Par défaut
    J'ai changé ma fonction pour :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    protected function _initRouter () {
     
    	$config = new Zend_Config_Ini(APPLICATION_PATH.'/config/application.ini', APPLICATION_ENV);
    	$router = new Zend_Controller_Router_Rewrite();
    	$router->addConfig($config, 'routes');
    	var_dump($router);
     
    }
    qui me donne :

    object(Zend_Controller_Router_Rewrite)#27 (8) { ["_useDefaultRoutes":protected]=> bool(true) ["_routes":protected]=> array(1) { ["interet"]=> object(Zend_Controller_Router_Route_Regex)#29 (7) { ["_regex":protected]=> string(16) "i/(.+)/([0-9]+)/" ["_defaults":protected]=> array(2) { ["controller"]=> string(7) "interet" ["action"]=> string(5) "index" } ["_reverse":protected]=> NULL ["_map":protected]=> array(2) { [1]=> string(3) "seo" [2]=> string(2) "id" } ["_values":protected]=> array(0) { } ["_isAbstract":protected]=> bool(false) ["_matchedPath":protected]=> NULL } } ["_currentRoute":protected]=> NULL ["_globalParams":protected]=> array(0) { } ["_chainNameSeparator":protected]=> string(1) "-" ["_useCurrentParamsAsGlobal":protected]=> bool(false) ["_frontController":protected]=> NULL ["_invokeParams":protected]=> array(0) { } }
    Donc le fichier de config est bien pris en compte.

    Mais il ne semble pas prendre en compte la route car il va chercher le controler "i".

    Ne faut-il pas rajouter une ligne de type "addRoute" ou quelque chose du genre ?

  11. #11
    Membre averti
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2008
    Messages
    519
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Janvier 2008
    Messages : 519
    Points : 311
    Points
    311
    Par défaut
    En mettant en place mon controleur error, j'obtiens désormais l'erreur suivante :

    DEBUG INFOS :
    Exception de type: Zend_Controller_Dispatcher_Exception
    Invalid controller specified (i)
    envoyée dans /www/library/Zend/Controller/Dispatcher/Standard.php à la ligne 248
    lors de l'ouverture de http://www.ndd.dev/i/rouen/1/

  12. #12
    Membre averti
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2008
    Messages
    519
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Janvier 2008
    Messages : 519
    Points : 311
    Points
    311
    Par défaut
    Même avec cette configuration il n'y a pas de redirection :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    $router = Zend_Controller_Front::getInstance()->getRouter();
     
    $r = new Zend_Controller_Router_Route_Regex(
    	"i/([-\w]+)/(\d+)/",
    	array('controller' => 'interet', 'action' => 'index'), 
    	array(1 => 'seo', 2 => 'id'),
    	'i/%s/%d/'
    );
     
    $router->addRoute('interet', $r);
    var_dump($router);
    return $router;
    le var_dump() me retourne :

    object(Zend_Controller_Router_Rewrite)#6 (8) { ["_useDefaultRoutes":protected]=> bool(true) ["_routes":protected]=> array(1) { ["interet"]=> object(Zend_Controller_Router_Route_Regex)#8 (7) { ["_regex":protected]=> string(17) "i/([-\w]+)/(\d+)/" ["_defaults":protected]=> array(2) { ["controller"]=> string(7) "interet" ["action"]=> string(5) "index" } ["_reverse":protected]=> string(8) "i/%s/%d/" ["_map":protected]=> array(2) { [1]=> string(3) "seo" [2]=> string(2) "id" } ["_values":protected]=> array(0) { } ["_isAbstract":protected]=> bool(false) ["_matchedPath":protected]=> NULL } } ["_currentRoute":protected]=> NULL ["_globalParams":protected]=> array(0) { } ["_chainNameSeparator":protected]=> string(1) "-" ["_useCurrentParamsAsGlobal":protected]=> bool(false) ["_frontController":protected]=> object(Zend_Controller_Front)#11 (11) { ["_baseUrl":protected]=> NULL ["_controllerDir":protected]=> NULL ["_dispatcher":protected]=> NULL ["_invokeParams":protected]=> array(0) { } ["_moduleControllerDirectoryName":protected]=> string(11) "controllers" ["_plugins":protected]=> object(Zend_Controller_Plugin_Broker)#5 (3) { ["_plugins":protected]=> array(0) { } ["_request":protected]=> NULL ["_response":protected]=> NULL } ["_request":protected]=> NULL ["_response":protected]=> NULL ["_returnResponse":protected]=> bool(false) ["_router":protected]=> *RECURSION* ["_throwExceptions":protected]=> bool(false) } ["_invokeParams":protected]=> array(0) { } }
    Je pense que le problème se situe autre part que dans ce code, mais où ???

  13. #13
    Membre averti
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2008
    Messages
    519
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Janvier 2008
    Messages : 519
    Points : 311
    Points
    311
    Par défaut
    Le problème venait du regex :

    au lieu de de


+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Migration profil utilisateurs sur un nouveau domaine
    Par ghostrider95 dans le forum Windows Serveur
    Réponses: 13
    Dernier message: 10/12/2011, 17h12
  2. Réponses: 4
    Dernier message: 13/01/2011, 03h39
  3. [UrlRewrite] domain.com/US vers domain.com/pages/index.php?c=US
    Par MatthieuFourcade dans le forum Apache
    Réponses: 2
    Dernier message: 01/04/2010, 14h30
  4. [URL rewriting] domain.com vers domain.com/pages/index.php
    Par MatthieuFourcade dans le forum Apache
    Réponses: 3
    Dernier message: 01/04/2010, 14h28

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