-1

I am trying to create a shopping cart for my website, I am following the tutorial below: https://www.youtube.com/watch?v=tRh467FX12U&list=PLfdtiltiRHWH9JN1NBpJRFUhN96KBfPmd&index=2

In the tutorial, he uses 3 different imports from GitHub and this is how installed them in the terminal using composer:

rosscurrie = Name of ~user

@Ross-Air = Name of Macbook

MobileMastersNew = Name of the folder that holds all website files

composer = is installed globally

require <...> = the imports from GitHub

  1. rosscurrie@Rosss-Air MobileMastersNew % composer require slim/slim:^4.0
  2. rosscurrie@Rosss-Air MobileMastersNew % composer require slim/twig-view:^3.0
  3. rosscurrie@Rosss-Air MobileMastersNew % composer require php-di/slim-bridge
  4. rosscurrie@Rosss-Air MobileMastersNew % composer require illuminate/database

I have limited experience with Laravel but not completely unfamiliar. When I try to load the index.php page it gets this error:

Fatal error: Uncaught Error: Class 'DI\Bridge\Slim\App' not found in /Users/rosscurrie/Sites/MobileMastersNew/app/App.php:8 Stack trace: #0 /Users/rosscurrie/Sites/MobileMastersNew/vendor/composer/ClassLoader.php(444): include() #1 /Users/rosscurrie/Sites/MobileMastersNew/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile('/Users/rosscurr...') #2 [internal function]: Composer\Autoload\ClassLoader->loadClass('Cart\\App') #3 /Users/rosscurrie/Sites/MobileMastersNew/bootstrap/app.php(9): spl_autoload_call('Cart\\App') #4 /Users/rosscurrie/Sites/MobileMastersNew/public/index.php(3): require('/Users/rosscurr...') #5 {main} thrown in /Users/rosscurrie/Sites/MobileMastersNew/app/App.php on line 8

My folder directory is as follows:

enter image description here

My ../MobileMasters/app/App.php is:

<?php

namespace Cart;

use DI\ContainerBuilder;
use DI\Bridge\Slim\App as DIBridge;

class App extends DIBridge
{
    protected function configureContainer(ContainerBuilder $builder)
    {
        $builder->addDefinitions([
           'settings.displayErrorDetails' => true,
        ]);

        //
    }
}

My ../MobileMasters/bootstrap/app.php is:

<?php

session_start();

use Cart\App;

require __DIR__ . '/../vendor/autoload.php';

$app  = new App;

My ../MobileMasters/public/.htaccess file is:

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

My ../MobileMasters/public/index.php is:

<?php

require __DIR__ . '/../bootstrap/app.php';

$app->run();

My ../MobileMasters/vendor/autoload.php is:

<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit2e9ebb4be0f95ed0dbfb26486b8ba4b7::getLoader();

Lastly, my ../MobileMasters/composer.json is:

{
    "require": {
        "slim/slim": "^4.0",
        "slim/twig-view": "^3.0",
        "php-di/slim-bridge": "^3.0",
        "illuminate/database": "^7.2"
    },
    "autoload": {
        "psr-4": {
            "Cart\\": "app"
        }
    }
}
halfer
  • 19,824
  • 17
  • 99
  • 186
RC07JNR
  • 535
  • 1
  • 8
  • 24
  • Did you install packages using composer? Did you run `composer require slism/slim`? – train_fox Mar 23 '20 at 11:47
  • @train_fox yes I did that was step 1. at the top: composer require slim/slim:^4.0 – RC07JNR Mar 23 '20 at 11:50
  • 1
    The tutorial is using Slim 3 and an older version of slim-bridge. If you want to follow the tutorial, you need to use the same version of packages that are used in the tutorial. Or, you can use newer versions of these packages and adopt required changes. For example, in newer version of slim-bridge there is no such class `DI\Bridge\Slim\App`. – Nima Mar 23 '20 at 13:25

3 Answers3

1

You should use use statement after autoloading:

<?php

namespace Cart;

use DI\ContainerBuilder;
use DI\Bridge\Slim\App as DIBridge;

class App extends DIBridge
{
    protected function configureContainer(ContainerBuilder $builder)
    {
        $builder->addDefinitions([
           'settings.displayErrorDetails' => true,
        ]);

        //
    }
}

And change this file also:

session_start();

require __DIR__ . '/../vendor/autoload.php';
use Cart\App;

$app  = new App;
train_fox
  • 1,517
  • 1
  • 12
  • 31
0

You are using wrong namespace use DI\Bridge\Slim\App as DIBridge;. There is no App class in DI package anymore.

Instead

use the following code use DI\Bridge\Slim\Bridge as DIBridge;

Gursewak Singh
  • 642
  • 1
  • 7
  • 20
0

Your composer.json needs to look almost exactly like the one in the tutorial. I had the exact same problem. To require the older versions, you just have to do something like composer remove slim/slim then composer require slim/slim ^3.0.

In particular, the your php-di needs to be lower than v1.1. My composer.json:

{
    {
    "require": {
        "slim/slim": "^3.0",
        "slim/twig-view": "^2.1",
        "illuminate/database": "^5.2",
        "php-di/slim-bridge": "v1.0.2"
    },
    "autoload": {
        "psr-4": {
            "Cart\\": "app/"
        }
    }
}
gummibear
  • 1
  • 1