I'm building my own MVC framework (to improve my PHP) but I don't know how to deal with good practices.
In my Router I have a method to create a link by using a route-name and the parameters (the method returns the well formatted url), so in my controllers I can use something like:
//inside an action of any of my controllers
$router = Router::getInstance(); //the router is a Singleton
$url = $router->createUrl('articleReadOne', array(65, 'matrix')); //$url = "article/read/65-matrix"
$this->redirectTo($url);
Or inside my views:
//inside a view
<?php $router = Router::getInstance(); ?>
<a href="<?php echo $router->createUrl('article-read', array(65, 'matrix')); ?>"> Click me </a>
But I can read all over the net that using Singleton is a bad practice (even for a Database class).
I really need to have access to my createUrl() method from inside my controller and from inside my Views, but if I don't use a Singleton Router class, how can I "inject" my Router to my Controllers and be able to use it? Is it really bad to use Singleton in a case like this?
Thank you for your help.
$controller->listAction($router, $otherStuff)or similar