1
votes

I am trying to reuse a php file for aa assignment. So the following line in index.php

require '.././library/Slim/Slim.php';

gives me the error message:

404 Page Not Found

The page you are looking for could not be found. Check the address bar to ensure your URL is spelled correctly. If all else fails, you can visit our homepage at the link below.

the folder library is one step backward relative to the file index.php. The file is present and I believe the path is correct because when I change the line to

require '.././library/Slim/Slim2.php'; //file Slim2.php not present

I get this error message instead

Warning: require(.././library/Slim/Slim.php2): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/Julio/Temperature/api/index.php on line 6

Fatal error: require(): Failed opening required '.././library/Slim/Slim.php2' (include_path='.:/Applications/XAMPP/xamppfiles/lib/php') in /Applications/XAMPP/xamppfiles/htdocs/Julio/Temperature/api/index.php on line 6

What's wrong? Using a MAC

2
One folder back would be '../library/Slim/Slim.php'; - RiggsFolly
You're right but it gives the 1st error message. I doubt that the path is the problem. I think that the problem should be something else - Rossygnol
Can we assume that you have checked that the account running the web server has access to that folder? - RiggsFolly
Cannot tell for sure. It's a folder that I have taken from another project. I have tried to unlock all files (using bash) in the folder though, just in case there were a locked file. I dont't know how to tell if the account running has access to the file/folder - Rossygnol
One test would be to allow anyone and anything to access it. If the problem goes away, then work out what account need access and make the security a bit more specific - RiggsFolly

2 Answers

1
votes

To expand on my comment, the error message you are receiving is one passed by Slim because it does not recognise the endpoint you are hitting.

So for example if you created your new Slim App instance with:

$app = new \Slim\App;

$app->get('/', function ($request, $response, $args) {
    // Logic for the root path here.
}

The above is not the best way to go about doing it, really you want to extract routes to their own file.

The full Slim documentation can be found here: http://www.slimframework.com/docs/

Edit: Just noticed you are using Slim2, my above examples are in Slim3 so there are some differences, however the solution to your current 404 should be the same. You need to create a route to handle the page you want to view and ensure you have your front controller set up correctly.

Edit2: Quickly wrote out the below to see if I could help you out anymore, pretty busy at the moment so I don't have enough time to go into this is any more detail. You should also be aware the below example set up is done in Slim3, and is very basic. There will be more optimal ways of setting up your folder structure, etc but this should give you a starting point. The main thing I would advise is to study some Slim Projects and the Slim documentation itself to get a good grasp of how the micro-framework works.

|- public
  |- index.php
  |- .htaccess
|- src
  |- ProjectName
    |- Routes
      |- example.php
    |- bootstrap.php
|- vendor

index.php

<?php 
// Pull in our bootstrap file.
require_once '../src/ProjectName/bootstrap.php';
$app->run();

.htaccess

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

bootstrap.php

<?php 
require_once '../vendor/autoload.php';
$app = new \Slim\App();
require_once 'Routes.php';

example.php

$app->get('/example/{name}', function ($request, $response, $args) {
    echo 'Hello ' . $args['name'];
}
0
votes

Make sure Apache doesn't ignore the .htaccess file because of the following Apache configuration AllowOverride none; check your virtual host configuration and add/amend to AllowOverride All:

   <Directory /var/www/site/example.com/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>