syacko
August 2, 2017, 3:26am
1
I have slim 3.0 installed and working, so long as I don’t change the default routing pattern in routing.php. I have read the website and looked several examples, no joy!
Routes.php:
<?php
// Routes
$app->get('/test', function ($request, $response, $args) {
// Sample log message
$this->logger->info("Slminfo '/' route");
// Render index view
return $this->renderer->render($response, 'index.phtml', array('name' => 'SLMINFO'));
});
$app->get('/[{name}]', function ($request, $response, $args) {
// Sample log message
$this->logger->info("Slminfo '/' route");
// Render index view
return $this->renderer->render($response, 'index.phtml', $args);
});
Then I run from the browser
{mydomain}/slminfo/public/index.php - works
{mydomain}/slminfo/public/ - works
and then
{mydomain}/slminfo/public/test - 404 not found
What am I doing wrong?
I’m in no way an expert as I’m just trying to get Slim to work myself but if I understand the routes correctly, the first parameter is the route pattern. Currently you have /test
but you are trying to access it using {mydomain}/slminfo/public/test
. Maybe your route should be something like this:
$app->get('/slminfo/public/test', function ($request, $response, $args) {
// Sample log message
$this->logger->info("Slminfo '/' route");
// Render index view
return $this->renderer->render($response, 'index.phtml', array('name' => 'SLMINFO'));
});
Using the route pattern /slminfo/public/test
instead. Unless you are using a group
for /slminfo/public
?
Just a thought.
syacko
August 2, 2017, 4:36pm
3
Thank you so much for your reply. The bad news is no it didn’t work.
$app->get(’/test’ - no
$app->get(’/public/test’ - no
$app->get(’/slminfo/public/test’ - no
syacko
August 2, 2017, 5:29pm
4
It turned out to be an ID10T issue! I was playing around with some rewrite rules and commented the following lines in .htaccess. See below:
RewriteEngine On
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^ index.php [QSA,L]
Everything works fine now.