The Slim instance is accessible through a Singleton and its getInstance
method
<a href="<?php echo Slim\Slim::getInstance()->urlFor('home'); ?>">my home link</a>
You can also specify a name if you have multiple instances of Slim
<a href="<?php echo Slim\Slim::getInstance('blog')->urlFor('home'); ?>">my home link</a>
If you want to access the urlFor method using $this
<a href="<?php echo $this->urlFor("home");">my home link</a>
Then you should create a Custom View by adding a subclass of Slim\View
containing a urlFor
method and link it to Slim
Custom class :
<?php
class CustomView extends \Slim\View
{
public function urlFor($name, $params = array(), $appName = 'default')
{
return Slim::getInstance($appName)->urlFor($name, $params);
}
}
Linking :
<?php
require 'CustomView.php';
$app = new \Slim\Slim(array(
'view' => new CustomView()
));