I'm loading my NavHelper class in every controller of my imcro MVC framework by injecting it into my abstract controller. But should I really inject it in there?
The NavHelper class is actually meant for the View. It's got a static function that returns a dynamically built array of navigation items based on the current request URI. But how would I use that directly in a View since Views aren't suppose to worry about object creation?
Otherwise I'd have to load it in the controller like I'm doing now, and just repeat the following in every controller, which isn't DRY and then send that to the View.
View::render('nav', $nav->get());
Controller.php
abstract class Controller
{
protected $req;
protected $nav;
public function __construct(Req $req, NavHelper $nav)
{
$this->req = $req;
$this->nav = $nav;
}
}