0

I got a problem with my application, on my dev environment everything works like it should. but on my hosting server, the php is interpreted but it does not show it in the browser, it just downloads a file.

the view is rendered with in slim/twig , when i make a json response instead of returning the view everything is okay.

 $apiEndpoints = json_decode(file_get_contents(__DIR__.'/ApiController/endpoints.json'));

    return $this->view->render($response, 'index.twig', [
        'apiEndpoints' => $apiEndpoints,
    ]);

the page is this one Application

I have the same environment on this server in another application there is no problem with this, I already downgraded slim/twig.

maybe someone see the problem in http header? I think it looks like it should.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Simon Müller
  • 451
  • 1
  • 4
  • 17
  • 1
    Is PHP installed on your server? – Ad5001 Feb 16 '17 at 21:03
  • Is there anything else in your callback that renders this template? – Georgy Ivanov Feb 16 '17 at 22:04
  • If you're using Apache, you might find a solution [here](http://stackoverflow.com/questions/18422140/apache-is-downloading-php-files-instead-of-displaying-them). I'd agree with @Ad5001Gameurcodeurautre, seems like php is not installed/enabled on your hosting server. – Georgy Ivanov Feb 17 '17 at 11:26

3 Answers3

2

Server is sending the response as application/x-httpd-php and your browser does not know what to do with it. Content type for HTML should be text/html.

$ curl --include http://app.uhc-scorpions.ch/

HTTP/1.1 200 OK
Date: Fri, 17 Feb 2017 06:34:52 GMT
Server: Apache/2.2.22 (Debian)
X-Powered-By: PHP/7.0.10
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Set-Cookie: userSession_Session=2quum1alcu5siipkim6qmdqul2; path=/; HttpOnly
Content-Length: 6310
Content-Type: application/x-httpd-php
Mika Tuupola
  • 19,877
  • 5
  • 42
  • 49
  • hmm okay i already tried to change that with `header('Content-Type: htm/text'); ` and `$response->withHeader('Content-type', 'text/html');` but that did not work ... a also tried to do some stuff in the htaccess file... maybe a hint how i can force slim/twig to change the response header – Simon Müller Feb 17 '17 at 13:28
0

thanks for all your posts it looks like i am to stupid for the slim framework :)

NOT WORKING:

 $response->withHeader('Content-type', 'text/html');
    return $this->view->render($response, 'index.twig', [
        'apiEndpoints' => $apiEndpoints,
    ]);

WORKING:

 return $this->view->render($response->withHeader('Content-type', 'text/html'), 'index.twig', [
        'apiEndpoints' => $apiEndpoints,
    ]);

now it works

Simon Müller
  • 451
  • 1
  • 4
  • 17
-3

I don't know about your code and architecture, but why should the view make the rendering? Make much sense that twig make the rendering of the view. So this :

return $this->view->render(

Should much look like this :

return $twig->render($this->view, array(...
Iteration
  • 494
  • 2
  • 7
  • 18
  • 1
    Presumably his Twig object is just added to the container with the `view` key. It's not the view doing the rendering. – Bytewave Feb 16 '17 at 21:16
  • He uses Slim's Twig-View, therfore the first argument should be response object. See [the source](https://github.com/slimphp/Twig-View/blob/master/src/Twig.php#L114). – Georgy Ivanov Feb 16 '17 at 22:07
  • hey thanks for trieng to help ... but the render function should work fine, on my dev vagrant box everything works – Simon Müller Feb 16 '17 at 22:30