# Container Resolution (with Code)

**URL:** <https://discourse.slimframework.com/t/container-resolution-with-code/128>\
**Category:** Questions\
**Created:** [April 13, 2016, 5:11pm UTC](https://discourse.slimframework.com/t/container-resolution-with-code/128 "2016-04-13T17:11:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bjones1831](https://avatars.discourse-cdn.com/v4/letter/b/35a633/32.png) [@bjones1831](https://discourse.slimframework.com/u/bjones1831)\
**Post date:** [April 13, 2016, 5:11pm UTC](https://discourse.slimframework.com/t/container-resolution-with-code/128/1 "2016-04-13T17:11:45Z")

</div>

Container Resolution

Similar to [Controllers Help](http://discourse.slimframework.com/t/container-resolution/107)

I’m trying to use Container Resolution to keep my index.php page from getting too big.  
I’m definitely a beginner to Slim. And I’m trying to follow the instructions from :

[http://www.slimframework.com/docs/objects/router.html#container-resolution](http://www.slimframework.com/docs/objects/router.html#container-resolution)

But I’m missing something.  
When I go to {domain\_name}/method1 in my browser, I get the error message :

**Slim Application Error**  
**A website error has occurred. Sorry for the temporary inconvenience.**

However, {domain\_name}/org works fine.

For the **/org route** I’m using the “require\_once” option (see **“org.php”** below). While this will help to keep the index.php file small, I would rather use Container Resolution.

Like I said, I know I’m missing something obvious.  
Can someone help me?

Thanks

Below is information on my file structure and relevant files

* * *

## **FOLDER STRUCTURE** :

/usr/share/nginx/html

```
index.php
MyController.php
org.php

/src

	autoload.php	<< #1 >>

/vendor

	autoload.php	<< #2 >>

	/composer
	/container-interop
	/nikic
	/pimple
	/psr
	/slim

```

* * *

## **_index.php_**
\<?php use \Psr\Http\Message\ServerRequestInterface as Request; use \Psr\Http\Message\ResponseInterface as Response; require 'vendor/autoload.php'; $app = new \Slim\App(); // NOT Working ... $app-\>get('/method1', '\MyController:method1'); // Working! require\_once('org.php'); $app-\>run(); ------------------------------- \*\*\_MyController.php\_\*\* ------------------------------- \<?php class MyController { protected $ci; //Constructor public function \_\_construct(ContainerInterface $ci) { $this-\>ci = $ci; } public function method1($request, $response, $args) { /\* NONE OF THE METHODS BELOW WORK \*/ // return $response-\>write("Method1"); // $this-ci-\>get('Method1'); // echo "Method1"; } public function method2($request, $response, $args) { //your code //to access items in the container... $this-\>ci-\>get(''); } public function method3($request, $response, $args) { //your code //to access items in the container... $this-\>ci-\>get(''); } } ------------------------------- \*\*\_org.php\_\*\* ------------------------------- \<?php $app-\>get('/org', function() { echo json\_encode("Your Organization Page"); }); ------------------------------- \_\*\*/src/\*\*\_ \_\*\*autoload.php \<\>\*\*\_ ------------------------------- \<?php require 'vendor/autoload.php'; ------------------------------- \_\*\*/vendor/\*\*\_ \_\*\*autoload.php \<\>\*\*\_ ------------------------------- \<?php require\_once \_\_DIR\_\_ . '/composer' . '/autoload\_real.php'; return ComposerAutoloaderInitc888888ddddafdagdadfagd::getLoader();

---

<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:** [April 13, 2016, 5:40pm UTC](https://discourse.slimframework.com/t/container-resolution-with-code/128/2 "2016-04-13T17:40:07Z")

</div>

Hi Bryan,

It looks as though you might not have created the container, or if you have you are not passing it to your application. See the [Application Configuration](http://www.slimframework.com/docs/objects/application.html#application-configuration) section of the docs. Specifically look at how the container `$config` is being passed to the application.

You may wish to start exploring Slim by having a look at the [Slim Skeleton](https://github.com/slimphp/Slim-Skeleton) for a little bit more of a working example, then try the code you see in the Container Resolution section of the docs.

---

<div class="post-metadata">

**Author:** ![bjones1831](https://avatars.discourse-cdn.com/v4/letter/b/35a633/32.png) [@bjones1831](https://discourse.slimframework.com/u/bjones1831)\
**Post date:** [April 14, 2016, 5:50am UTC](https://discourse.slimframework.com/t/container-resolution-with-code/128/3 "2016-04-14T05:50:49Z")

</div>

Thanks Tim!

I’ll check out the skeleton, and take another look at the App Config section in the docs.
