# Route with parameters get 404

**URL:** <https://discourse.slimframework.com/t/route-with-parameters-get-404/1828>\
**Category:** Questions\
**Created:** [September 22, 2017, 12:07pm UTC](https://discourse.slimframework.com/t/route-with-parameters-get-404/1828 "2017-09-22T12:07:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bia](https://avatars.discourse-cdn.com/v4/letter/b/ecc23a/32.png) [@bia](https://discourse.slimframework.com/u/bia)\
**Post date:** [September 22, 2017, 12:07pm UTC](https://discourse.slimframework.com/t/route-with-parameters-get-404/1828/1 "2017-09-22T12:07:51Z")

</div>

I’ve the code bellow, when I pass:

> localhost/api/empresas

It works, but when I tried a route with parameters like:  
` localhost/api/empresas/1`,

I got:  
Page Not Found  
The page you are looking for could not be found. Check the address bar to ensure your URL is spelled correctly. If all else fails, you can visit our home page at the link below.

Here’s my code:

Index.php:

```
<?php 
require 'vendor/autoload.php';

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

use App\Controllers\EmpresasController;

$app = new \Slim\App([
    'settings' => [
        'displayErrorDetails' => true,
    ]
]);

$container = $app->getContainer();

$container['db']= function($container){
	return new PDO('pgsql:host=localhost;port=5432;dbname=base', 'root', '123');
};

$container['EmpresasController'] = function($container) use ($app){
	return new App\controllers\EmpresasController($container);
};

$app->get('/', 'EmpresasController:index')->setName('home');

$app->get('/empresas', 'EmpresasController:listarTodasEmpresas')->setName('empresas');

$app->get('/empresas/{$id}', 'EmpresasController:empresaPorId')->setName('empresaPorId');

```

EmpresasController.php:

```
<?php 
namespace App\controllers;

class EmpresasController extends Controller 
{
    
    public function index($request, $response, $args){
		print_r($args);
	}

	public function listarTodasEmpresas($request, $response, $args){
		
		$stmt = $this->db->prepare("SELECT * FROM empresa");
		$stmt->execute();
		
		$customers = $stmt->fetchAll();

		echo json_encode($customers);
	}

	public function empresaPorId($request, $response, $args){
		
		print_r($args);

	}
}

```

And my .htaccess:

RewriteEngine On  
RewriteCond %{SCRIPT\_FILENAME} !-f  
RewriteCond %{SCRIPT\_FILENAME} !-d  
RewriteRule ^(.\*)$ index.php [QSA,L]

---

<div class="post-metadata">

**Author:** ![tstadler](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tstadler](https://discourse.slimframework.com/u/tstadler)\
**Post date:** [September 22, 2017, 1:09pm UTC](https://discourse.slimframework.com/t/route-with-parameters-get-404/1828/2 "2017-09-22T13:09:19Z")

</div>

Hi,

pleas try

$app-\>get(’/empresas/{id}’, ‘EmpresasController:empresaPorId’)-\>setName(‘empresaPorId’);

instead of

$app-\>get(’/empresas/{$id}’, ‘EmpresasController:empresaPorId’)-\>setName(‘empresaPorId’);

---

<div class="post-metadata">

**Author:** ![bia](https://avatars.discourse-cdn.com/v4/letter/b/ecc23a/32.png) [@bia](https://discourse.slimframework.com/u/bia)\
**Post date:** [September 22, 2017, 1:24pm UTC](https://discourse.slimframework.com/t/route-with-parameters-get-404/1828/3 "2017-09-22T13:24:08Z")

</div>

> [@bia](#):
>
> localhost/api/empresas
> 
> It works, but when I tried a route with parameters like:
> 
> localhost/api/empresas/1,
> 
> I got:
> 
> Page Not Found
> 
> The page you are looking for could not be found. Check the address bar to ensure your URL is spelled correctly. If all else fails, you can visit our home page at the link below.
> 
> Here’s my code:
> 
> Index.php:

Exactly this, solved, thanks.
