Fatal error: Uncaught Phroute\Phroute\Exception\HttpRouteNotFoundException: Route ecomselim does not exist in
mofizul21 opened this issue · 2 comments
Hi,
Thanks a lot for making this frameowork for us.
But I've an issue. I've installed PHRoute successfully and my code is here-
`use Phroute\Phroute\Dispatcher;
use Phroute\Phroute\RouteCollector;
use Phroute\Phroute\RouteParser;
require_once 'vendor/autoload.php';
$router = new RouteCollector(new RouteParser());
$router->get('/', function(){
return "Hello World";
});
$dispatcher = new Dispatcher($router->getData());
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
echo $response;`
It should display "Hello World" in my homepage. But I see an error in my browser
Fatal error: Uncaught Phroute\Phroute\Exception\HttpRouteNotFoundException: Route ecomselim does not exist in C:\xampp\htdocs\ecomselim\vendor\phroute\phroute\src\Phroute\Dispatcher.php:218 Stack trace: #0 C:\xampp\htdocs\ecomselim\vendor\phroute\phroute\src\Phroute\Dispatcher.php(123): Phroute\Phroute\Dispatcher->dispatchVariableRoute('GET', 'ecomselim') #1 C:\xampp\htdocs\ecomselim\vendor\phroute\phroute\src\Phroute\Dispatcher.php(47): Phroute\Phroute\Dispatcher->dispatchRoute('GET', 'ecomselim') #2 C:\xampp\htdocs\ecomselim\index.php(15): Phroute\Phroute\Dispatcher->dispatch('GET', '/ecomselim/') #3 {main} thrown in C:\xampp\htdocs\ecomselim\vendor\phroute\phroute\src\Phroute\Dispatcher.php on line 218
Where is my problem? How to I can fix it?
Regards,
Mofizul
Just change this part
$router->get('/ecomselim ', function(){
return "Hello World";
});
- Did you create an .htaccess file ?
If not create it in your project folder (➡️ C:\xampp\htdocs\ecomselim\ ).
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ecomselim/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ecomselim/index.php [L]
</IfModule>
- You project is in a subdirectory, so you must use router like this
/* to make it simple, this is your folder name */
$base = '/ecomselim';
$router->get( $base . '/ ' , function() {
return "Hello World";
});