klein/klein.php

$this->PageTitle is not working

Closed this issue · 2 comments

I receive only 500 internel error on doing echo of $this->pageTitle.
image

index.php

// Test page
$klein->respond('/test', function ($request, $response, $service) {
    $service->pageTitle = 'Home page';
    $service->render('views/test.php');
});
$klein->dispatch();

test.php
<?= $this->pageTitle; ?>

Probably need to start by looking at the error output. Depending on your server's PHP config, it might be in the body of the response, or it might be in your Apache/Nginx logs.

At first glance, that code looks fine. Not that many moving parts here, which is nice. Maybe it can't find test.php? I can't remember how it handles relative paths. That has tripped me up in other situations, so I'm kind of paranoid about it now. I generally use __DIR__ all the time to be safe:

$service->render(__DIR__.'/views/test.php');

I think some PHP configs also disable the <?= syntax in favor of the more verbose <?php echo. Not a fan personally, but people do it. If that's the case, you'd need to tweak your PHP config, or use the more verbose syntax.

Those are my 2 best guesses. The error output should make it clear if it's either of those things, or something entirely different I've failed to notice.

Thank you for the reply. I fixed that by updating .htaccess by following

<IfModule mod_rewrite.c>
    Options -MultiViews

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>