samir
samir

Reputation: 137

Slim framework is not working

Currently I am using ubuntu and I would like to install PHP Slim framework in my system.

I have install composer through command line and also manually install Slim framework then I have created a index.php file in slim folder and put following code in that file and when I try to run that file does not see.

<?php
require 'vendor/autoload.php';

$app = new SlimApp();
//slim application routes
$app->get('/', function ($request, $response, $args) { 
 $response->write("Welcome: This is AlphansoTech Tutorial Guide");
 return $response;
});
$app->run()
?>

I tried to call http://localhost/slim/index.php, showing me blank screen.

I don't know what happen first time i am installing and using slim framework.

I tried following url for installing slim framework.

http://www.alphansotech.com/blogs/php-restful-api-framework-slim-tutorial/

https://www.slimframework.com/docs/tutorial/first-app.html

https://www.slimframework.com/docs/start/installation.html

How to install or run api using slim framework?

Upvotes: 1

Views: 3651

Answers (3)

Pau Homs
Pau Homs

Reputation: 1

I think the problem is in the creation of the $app. The way that works for me to create an application is:

use Slim\Factory\AppFactory;

$app = AppFactory::create();

Upvotes: 0

Ramy hakam
Ramy hakam

Reputation: 542

Slim can not find vendor folder which contains all Slim files and other dependencies required in your composer.json

You must install all dependencies first

Run This commend from your Project directory

composer install 

Then Check your Routes Again. If you don't have the Composer visit getcomposer.org first.

Upvotes: 1

Suresh
Suresh

Reputation: 5987

Here is my Slim code which I installed by using composer.

index.php

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

require 'vendor/autoload.php';

$app = new \Slim\App;
$app->get('/hello/{name}', function (Request $request, Response $response) {
    $name = $request->getAttribute('name');
    $response->getBody()->write("Hello, $name");

    return $response;
});
$app->run();

My URL for accessing the file is http://localhost/slim/index.php/hello/suresh

Installation folder name - slim

Output Received

Hello, suresh

Documentation followed from - https://www.slimframework.com/

Hope, it'll give you some hint to solve your problem.

Upvotes: 0

Related Questions