Probleme $ premiere page

Par arcoss 3x, il y a 10 ans


Bonjour je viens de regarder le tutoriel php jour 4 et j'ai un probleme sur ma premiere page :

Call Stack # Time Memory Function Location 1 0.0006 247416 {main}( ) ..\index.php:0 2 0.0146 360376 Dispatcher->__construct( ) ..\index.php:9 3 0.0146 360824 Router::parse( ) ..\Dispatcher.php:8 4 0.0146 361000 preg_match ( ) ..\Router.php:17 ( ! ) Warning: preg_match(): Unknown modifier '$' in C:\wamp\www\emmy\core\Router.php on line 17 Call Stack # Time Memory Function Location 1 0.0006 247416 {main}( ) ..\index.php:0 2 0.0146 360376 Dispatcher->__construct( ) ..\index.php:9 3 0.0146 360824 Router::parse( ) ..\Dispatcher.php:8 4 0.0163 361968 preg_match ( ) ..\Router.php:17 ( ! ) Warning: preg_match(): Unknown modifier '$' in C:\wamp\www\emmy\core\Router.php on line 17 Call Stack # Time Memory Function Location 1 0.0006 247416 {main}( ) ..\index.php:0 2 0.0146 360376 Dispatcher->__construct( ) ..\index.php:9 3 0.0146 360824 Router::parse( ) ..\Dispatcher.php:8 4 0.0199 361968 preg_match ( ) ..\Router.php:17

router.php :

<?php class Router{ static $routes = array(); /** * Permet de parser une url * @param $url Url à parser * @return tableau contenant les paramètres **/ static function parse($url,$request){ $url = trim($url, '/'); if(empty($url)){ $url = Router::$routes[0]['url']; }else{ foreach(Router::$routes as $v){ if(preg_match($v['catcher'],$url,$match)){ $request->controller = $v['controller']; $request->action = isset($match['action']) ? $match['action'] : $v['action']; $request->params = array(); foreach($v['params'] as $k=>$v){ $request->params[$k] = $match[$k]; } if(!empty($match['args'])){ $request->params += explode('/',trim($match['args'],'/')); } return $request; } } } $params = explode('/',$url); $request->controller = $params[0]; $request->action = isset($params[1]) ? $params[1] : 'index'; $request->params = array_slice($params,2); return true; } static function connect($redir,$url){ $r = array(); $r['params'] = array(); $r['url'] = $url; $r['redir'] = $redir; $r['origin'] = str_replace(':action','(?P<action>([a-z0-9]+))',$url); $r['origin'] = preg_replace('/([a-z0-9]+):([^\/]+)/','${1}:(?P<${1}>${2})',$r['origin']); $r['origin'] = '/^'.str_replace('/','\/', $r['origin']).'(?P<args>\/?.*)$/'; $params = explode('/',$url); foreach($params as $k=>$v){ if(strpos($v,':')){ $p = explode(':',$v); $r['params'][$p[0]] = $p[1]; }else{ if($k==0){ $r['controller'] = $v; }elseif($k==1){ $r['action'] = $v; } } } $r['catcher'] = $redir; $r['catcher'] = str_replace(':action','(?P<action>([a-z0-9]+))',$r['catcher']); foreach($r['params'] as $k=>$v){ $r['catcher'] = str_replace(":$k","(?P<$k>$v)",$r['catcher']); } $r['catcher'] = '/^'.str_replace('/','\/', $r['catcher']).'(?P<args>\/?.*)/$'; self::$routes[] = $r; } static function url($url){ foreach(self::$routes as $v){ if(preg_match($v['origin'],$url,$match)){ foreach($match as $k=>$w){ if(!is_numeric($k)){ $v['redir'] = str_replace(":$k",$w,$v['redir']); } } return BASE_URL.'/'.$v['redir'].$match['args']; } } return BASE_URL.'/'.$url; } } ?>

6 réponses

arcoss 3x, il y a 10 ans

il contient un array() ...

arcoss 3x, il y a 10 ans

Et j'ai aussi un probleme quand je fais lire la suite dans actualités :

( ! ) Warning: preg_match(): Unknown modifier '$' in C:\wamp\www\emmy\core\Router.php on line 17 Call Stack # Time Memory Function Location 1 0.0004 247464 {main}( ) ..\index.php:0 2 0.0114 360392 Dispatcher->__construct( ) ..\index.php:9 3 0.0114 360840 Router::parse( ) ..\Dispatcher.php:8 4 0.0114 361024 preg_match ( ) ..\Router.php:17 ( ! ) Warning: preg_match(): Unknown modifier '$' in C:\wamp\www\emmy\core\Router.php on line 17 Call Stack # Time Memory Function Location 1 0.0004 247464 {main}( ) ..\index.php:0 2 0.0114 360392 Dispatcher->__construct( ) ..\index.php:9 3 0.0114 360840 Router::parse( ) ..\Dispatcher.php:8 4 0.0132 361992 preg_match ( ) ..\Router.php:17 ( ! ) Warning: preg_match(): Unknown modifier '$' in C:\wamp\www\emmy\core\Router.php on line 17 Call Stack # Time Memory Function Location 1 0.0004 247464 {main}( ) ..\index.php:0 2 0.0114 360392 Dispatcher->__construct( ) ..\index.php:9 3 0.0114 360840 Router::parse( ) ..\Dispatcher.php:8 4 0.0148 361992 preg_match ( ) ..\Router.php:17 ( ! ) Warning: require(C:\wamp\www\emmy\controller\PostController.php): failed to open stream: No such file or directory in C:\wamp\www\emmy\core\Dispatcher.php on line 25 Call Stack # Time Memory Function Location 1 0.0004 247464 {main}( ) ..\index.php:0 2 0.0114 360392 Dispatcher->__construct( ) ..\index.php:9 3 0.0163 362400 Dispatcher->loadController( ) ..\Dispatcher.php:9 ( ! ) Fatal error: require(): Failed opening required 'C:\wamp\www\emmy\controller\PostController.php' (include_path='.;C:\php\pear') in C:\wamp\www\emmy\core\Dispatcher.php on line 25 Call Stack # Time Memory Function Location 1 0.0004 247464 {main}( ) ..\index.php:0 2 0.0114 360392 Dispatcher->__construct( ) ..\index.php:9 3 0.0163 362400 Dispatcher->loadController( ) ..\Dispatcher.php:9

merci d'avance !

Alexandre #lbac, il y a 10 ans

Il faudrait apprendre à débuguer son code soi même un peu ;)

arcoss 3x, il y a 10 ans

je vais y travailler mais c pas simple pour moi ... Pourquoi vous avez trouvé ?

arnich, il y a 10 ans

a cette heure je te conseille de mettre des var_dump dans ton code. Voir ce que contient $route par exemple.

arcoss 3x, il y a 10 ans

c'était un probleme de code ...