Sunday, 15 September 2013

Using Auryn or Pimple as a DIC in a simple MVC use case

Using Auryn or Pimple as a DIC in a simple MVC use case

I have the following example:
# bootstrap.php
define(DICTIONARY_PATH, '/dictionary/en_EN.dic');
------------------------------------------------------------------------
# /Model/User.php (active record)
class User {
public $Id;
public $Language;
public static function LoadById($intId) {
...
}
}
------------------------------------------------------------------------
# /Controller/UserController.php
class UserController {
protected $objUser;
public function __construct() {
$this->objUser = User::LoadById($_GET['id'));
}
public function showPage() {
$objDictionary = new Dictionary(DICTIONARY_PATH,
$this->objUser->Language);
...
}
}
------------------------------------------------------------------------
# /Model/Dictionary.php
class Dictionary {
public function __construct($strPath, $strLanguage) {
...
}
}
What I wish to know is how to use properly a PHP DIC library to solve the
following problems:
create the dictionary object inside the bootstrap file, because it's used
a lot in the application(the main problem is the second constructor param:
language is variable)
how can I pass the user object to the UserController in the constructor?

No comments:

Post a Comment