If I render an actual html site with external dependencies (javascript/css) using
$app->render("./somewhere/index.html");
or
echo "<html>...</html>";
for some reason slim cant resolve the dependency paths - so the site can't be loaded correctly. An workaround is $app->redirect("./somewhere/index.html"); instead of $app->render("./somewhere/index.html"); - but then also the URL path in browsers adress bar changes. I want to avoid that, because I just want to display an HTML template for the REST request I'm receiving from the URI - so theres no point to redirect to an html document and lose the REST Parameters.
An sscce for my problem:
dir structure:
- index.php
+ templates
|-- index.html
|-- dependency.js
+ Slim
|-- ...
|-- ...
index.php:
<?php
require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new Slim\Slim();
$app->get('/:id', function ($id) use ($app) {
$app->render('index.html');
});
$app->run();
?>
/templates/index.html:
<html>
<head>
<title>SSCCE</title>
<script id="someid" type="text/javascript" src="dependency.js"></script>
</head>
<body>
<a href="javascript:func_test()">Click here</a>
</body>
</html>
/templates/dependency.js:
function func_test() {
alert("Test");
}
1.) Success: Access the /templates/index.html directly. (i.e. by entering 127.0.0.1/templates/index.html). Clicking on 'Click here' opens a message box.
2.) Failure: Access the index.php File from Slim (note: I haven't activated mod_rewrite on the webserver - so I'm using index.php/.../ as URI i.e. 127.0.0.1/index.php/testid). The html site loads correctly, but if I click on 'Click here' nothing happens.
I already tried: different variants of src="../dependency.js", src="../templates/dependency.js", changing index.html into an php file and using src="$webroot/templates/dependency.js" - but nothing worked. Any idea how to fix this?