My Project:
App
|-----Controllers
|-----Controllers/Controler.php
|-----Controllers/Admin\HomeControler.php
|-----Models
|-----Models\User.php
App.php
$container['db'] = function ($container) {
return new App\Helpers\Database($container['settings']['db']);
};
Controller.php
namespace App\Controllers;
use Interop\Container\ContainerInterface;
class Controller
{
protected $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public function __get($property)
{
if ($this->container->{$property}) {
return $this->container->{$property};
}
}
}
HomeController.php
namespace App\Controllers\Admin;
use App\Models\User
Class HomeController extends Controller
public function index($request, $response, $agr)
{
// How to call Model here ? How do I have must to code Model ?
//Exp: $user = User::getUsername($agr['id']);
}
router.php
$this->get('', '\App\Controllers\Admin\HomeCtroller:index')->setName('home');
Final, my question at comment in HomeCtroller: How to call User Model or other Model enywhere ?