# Add value to route before

**URL:** <https://discourse.slimframework.com/t/add-value-to-route-before/5077>\
**Category:** Questions\
**Created:** [January 12, 2022, 2:13pm UTC](https://discourse.slimframework.com/t/add-value-to-route-before/5077 "2022-01-12T14:13:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dinesh](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@Dinesh](https://discourse.slimframework.com/u/Dinesh)\
**Post date:** [January 12, 2022, 2:13pm UTC](https://discourse.slimframework.com/t/add-value-to-route-before/5077/1 "2022-01-12T14:13:23Z")

</div>

Hi Folks i upgrading my slim framework from slim 2 to slim 4  
for one route i added the one value before route using slim 2 **slim.before**

example code:

```auto
$app->hook('slim.before', function () use ($app) {
    $env = $app->environment();
    $path = $env['PATH_INFO'];
    
    $uriArray = explode('/', $path);
    $dynamicvalue = 'value';
    if(array_key_exists($uriArray[1], array)) {
        $dynamicvalue = $uriArray[1];
        $path_trimmed = substr($path, strlen($dynamicvalue) + 1); 
        $env['PATH_INFO'] = $path_trimmed;
    }
  
});

```

i read about the middleware but i am not able to get correctly how to do it  
can any one help me to do with slim 4
