# How extend Slim\\App?

**URL:** <https://discourse.slimframework.com/t/how-extend-slim-app/5913>\
**Category:** Questions\
**Created:** [June 7, 2024, 2:06pm UTC](https://discourse.slimframework.com/t/how-extend-slim-app/5913 "2024-06-07T14:06:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jobasco](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/jobasco/32/1614_2.png) [@jobasco](https://discourse.slimframework.com/u/jobasco)\
**Post date:** [June 7, 2024, 2:06pm UTC](https://discourse.slimframework.com/t/how-extend-slim-app/5913/1 "2024-06-07T14:06:26Z")

</div>

Hi, i want extend the slim\app class but i am getting this error message.

[07-Jun-2024 13:06:51 UTC] PHP Fatal error: Uncaught TypeError: DI\Definition\Source\DefinitionFile::{closure}(): Argument #1 ($app) must be of type Ultra\Foundation\App, Slim\App given, called in /home/myphp/public\_html/myph/config/container.php on line 18 and defined in /home/myphp/public\_html/myphp/routes/web.php:12  
Stack trace:

This is what i have tried.  
App.php

```auto
<?php

declare(strict_types=1);

namespace Ultra\Foundation;

use Slim\App;
//use Slim\Factory\AppFactory;

class App extends Slim\App
{

```

i don’t know what i am doing wrong,  
i need help.

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [June 7, 2024, 4:04pm UTC](https://discourse.slimframework.com/t/how-extend-slim-app/5913/2 "2024-06-07T16:04:31Z")

</div>

Somewhere in you application you are passing a Slim\App instance instead of your custom App instance.

Check the file container.php on line 18 to see where it is coming from.

I guess it’s a incorrect `using` statement, because the classname is App in both cases.

---

<div class="post-metadata">

**Author:** ![jobasco](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/jobasco/32/1614_2.png) [@jobasco](https://discourse.slimframework.com/u/jobasco)\
**Post date:** [June 7, 2024, 4:55pm UTC](https://discourse.slimframework.com/t/how-extend-slim-app/5913/3 "2024-06-07T16:55:29Z")

</div>

Thanks, i will check and get back to you.

---

<div class="post-metadata">

**Author:** ![jobasco](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/jobasco/32/1614_2.png) [@jobasco](https://discourse.slimframework.com/u/jobasco)\
**Post date:** [June 7, 2024, 8:41pm UTC](https://discourse.slimframework.com/t/how-extend-slim-app/5913/4 "2024-06-07T20:41:39Z")

</div>

Still not working.  
this is my container.php

```auto
<?php

declare(strict_types=1);

use Psr\Container\ContainerInterface;
use Ultra\Foundation\App;
use Slim\Factory\AppFactory;
use Slim\Views\Twig;

return [
    'settings' => function () {
        return require __DIR__. '/../config/settings.php';
    },

App::class => function (ContainerInterface $container) {
    $app = AppFactory::createFromContainer($container);

    // Require routes
    (require __DIR__. '/../routes/web.php')($app);

    //Require middlewares
    (require __DIR__. '/../app/Http/Middlewares/middleware.php')($app);

      return $app;

},
    
   Twig::class => function (ContainerInterface $container): Twig {
        /** @var array<string, array<string, mixed>> $settings */
        $settings = $container->get('settings');
   
        $options = [
            'debug' => $settings['app']['debug'],
            'cache' => $settings['view']['cache'],
        ];

        /** @var string $path */
        $path = $settings['view']['path'];

        $twig = Twig::create($path, $options);

        /** @var Translator $translator */
        //$translator = $container->get(Translator::class);

        //$twig->getEnvironment()->addGlobal('locale', $translator->getLocale());
        //$twig->addExtension(new TranslationExtension($translator));

        return $twig;
    },

];

```

and this is my route/web.php

```auto
<?php

declare(strict_types=1);

use App\Controllers\AboutController;
use App\Controllers\ContactController;
use App\Http\Controllers\IndexController;

return static function (Ultra\Foundation\App $app): void {
    $app->get('/', [IndexController::class, 'index'])->setName('home.index');
    $app->get('/about', [AboutController::class, 'index'])->setName('about.index');
    $app->get('/contact', [ContactController::class, 'index'])->setName('contact.index');
};

```

Please take a look. thanks

---

<div class="post-metadata">

**Author:** ![akrabat](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/akrabat/32/9_2.png) [@akrabat](https://discourse.slimframework.com/u/akrabat)\
**Post date:** [June 8, 2024, 4:51pm UTC](https://discourse.slimframework.com/t/how-extend-slim-app/5913/6 "2024-06-08T16:51:54Z")

</div>

In `container.php`, you are using Slim’s `AppFactory` here:

```auto
$app = AppFactory::createFromContainer($container);

```

This returns in instance of `Slim\App` as you can see here: [Slim/Slim/Factory/AppFactory.php at 4.x · slimphp/Slim · GitHub](https://github.com/slimphp/Slim/blob/4.x/Slim/Factory/AppFactory.php#L103).

You will need your own `AppFactory`.

---

<div class="post-metadata">

**Author:** ![tiara](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tiara/32/1635_2.png) [@tiara](https://discourse.slimframework.com/u/tiara)\
**Post date:** [June 26, 2024, 10:01am UTC](https://discourse.slimframework.com/t/how-extend-slim-app/5913/7 "2024-06-26T10:01:31Z")

</div>

Thanks it helped me too:)

---

<div class="post-metadata">

**Author:** ![laylacollins](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/laylacollins/32/1638_2.png) [@laylacollins](https://discourse.slimframework.com/u/laylacollins)\
**Post date:** [July 11, 2024, 7:08am UTC](https://discourse.slimframework.com/t/how-extend-slim-app/5913/8 "2024-07-11T07:08:42Z")

</div>

Hello,  
Thanks for the solution ,this is very helpful for me.
