The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

Slim keep displaying 404 error - tried everything

Thomas's Avatar

Thomas

27 Aug, 2015 04:07 AM

Hi All, I have some problem with slim 2, i tried everything from different forums but still not working.
I believe the problem is in GET route.

Folder Structure

slim (root directory)
    app
        views (where all views are stored)
            home.php
        routes.php
        start.php
    public
        .htaccess
        index.php
    vendor
    composer.json

.htaccess (Located in public folder)

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

Index.php (Located in public folder)

<?php
require '../app/start.php';
$app->run();

Start.php (Located in app folder)

<?php
session_start();
require '../vendor/autoload.php';
$app = new \Slim\Slim([
    'view' => new \Slim\Views\Twig()
]);
$view = $app->view();
$view->setTemplatesDirectory('../app/views');
$view->parserExtensions = [
    new \Slim\Views\TwigExtension(),
];
require 'routes.php';

Routes.php (Located in app folder)

$app->get('/', function() use ($app) {
    echo "Hello World";
    //$app->render('home.php');
});

home.php (Located in views folder)

Home Template
(Currently not used in routes.php as I can't even echo out Hello World

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac