# Route Callable Prefix

**URL:** <https://discourse.slimframework.com/t/route-callable-prefix/1642>\
**Category:** Questions\
**Created:** [July 4, 2017, 9:37pm UTC](https://discourse.slimframework.com/t/route-callable-prefix/1642 "2017-07-04T21:37:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TechKat](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/techkat/32/447_2.png) [@TechKat](https://discourse.slimframework.com/u/TechKat)\
**Post date:** [July 4, 2017, 9:37pm UTC](https://discourse.slimframework.com/t/route-callable-prefix/1642/1 "2017-07-04T21:37:34Z")

</div>

Hello,

Probably been asked before, but I’m fairly new to Slim (and love it btw).

Coming off Laravel, they made it easier to use a Class::method without calling the full namespace (e.g App\Http\Controllers\Home\HomeController:class)

Is there anyway to modify/add something in Slim so that I can use shorter namespaces in routes?

For example, instead of doing:

`$app->get('/page', App\Http\Controllers\Home\HomeController:class);`

I’d like to do:

`$app->get('/page', Home\HomeController:class);`

but, the full namespace would still be like the first example, so the app knows to prefix “App\Http\Controllers” for every route that uses the class path.

I’ve read through the Router documentation, but I can’t seem to see if it’s possible.

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [July 4, 2017, 10:17pm UTC](https://discourse.slimframework.com/t/route-callable-prefix/1642/2 "2017-07-04T22:17:43Z")

</div>

Yes-- If you define your Controller in the container, Slim will find it there. See the [Container Resolution (Router Object)](https://www.slimframework.com/docs/objects/router.html#container-resolution) section of the docs for details.

---

<div class="post-metadata">

**Author:** ![TechKat](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/techkat/32/447_2.png) [@TechKat](https://discourse.slimframework.com/u/TechKat)\
**Post date:** [July 4, 2017, 10:29pm UTC](https://discourse.slimframework.com/t/route-callable-prefix/1642/3 "2017-07-04T22:29:26Z")

</div>

Doesn’t that require me to tell Slim to look in my App\Http\Controllers folder if I’m defining “\HomeController:class” in a route?

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [July 4, 2017, 10:33pm UTC](https://discourse.slimframework.com/t/route-callable-prefix/1642/4 "2017-07-04T22:33:19Z")

</div>

If you have something named `HomeController` in your container, that instantiates `App\Http\Controllers\HomeController`, you can then just use the shorthand `HomeController` in your routes.

Or, if you use PHP-DI instead of the provided Pimple, I believe that does support “[wildcard](http://php-di.org/doc/php-definitions.html#wildcards)” entries which could likely be used to do that without defining it in the container. PHP-DI also gives you autowiring via reflection.

---

<div class="post-metadata">

**Author:** ![1ma](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/1ma/32/314_2.png) [@1ma](https://discourse.slimframework.com/u/1ma)\
**Post date:** [July 5, 2017, 7:31am UTC](https://discourse.slimframework.com/t/route-callable-prefix/1642/5 "2017-07-05T07:31:48Z")

</div>

AFAIK this is a PHP feature, nothing to do with Slim. You can import specific classes or full namespaces and use the shorthand notation:

```
<?php

use Slim\App; // Class import
use App\Http\Controllers\Home; // Namespace import

$app = new App(); // rather than new \Slim\App();

$app->get('/page', Home\HomeController::class);

```

PD mind that you need to write two colons before the class keyword, not one.
