Slim doesn’t really have a concept of controller in the same way Silex does. You can however rewrite your code to look more like:
<?php
$app->get(’/browse/{path}’, function($request, $response) use ($app) {
// You will need to change self to the class name
$content = self::browse($app, $request->getAttribute('path'));
return $response->write($content);
});
$app->get(’/ajax/{path}’, function($request, $response) use ($app) {
$path = $request->getAttribute('path');
$target = DIR.’/…/data/’.$path;
if (!file_exists($target))
return $response->write(self::msg(False, “$path does not exist”));
if (is_dir($target))
return $response->write(self::get_content($app, $path));
else
return $response->write(file_get_contents($target));
});
I have no idea what self is in these instances, but you will need to replace that with the class name instead.
Still a small problem (in case you know the solution), I want Slim to want to return a file, in Silex I can use the sendFile helper method. It eases returning files that would otherwise not be publicly available. Simply pass it your file path, status code, headers and the content disposition and it will create a BinaryFileResponse response for you.
Does Slim have a similar function ?