Issue
I'm a total newbie and I'm merely piecing tutorials and use cases together to speed up my understanding of this new field, so apologies for not knowing what's going on.
Anyway, here's the situation: I'm using xampp as a test server to create a database driven website that includes a login page, a search page, and a profile page where you can subscribe to recurring packages using Stripe's API.
Following Stripe's instructions here: https://stripe.com/docs/billing/subscriptions/checkout, I copied all the code from Github to take care of step 4 and refreshed the index page, just to kind of see if there's something going on. I ended up getting this error:
Fatal error: Uncaught Error: Class "Dotenv\Dotenv" not found in C:\xampp\root\index.php:15
I downloaded composer using the windows installer, and right after, I verified by typing in 'composer' in the command terminal to see if it's working. At this point, I'm not sure what's going on. In the vendor directory, symfony, stripe and composer have their own folders.
Can someone help?
<?php
include "db_connect.php";
include "header.php"; //just some script and style sources, as well as the upper half of the html body tag
require_once("stripe-php/init.php");
use Slim\Http\Request;
use Slim\Http\Response;
use Stripe\Stripe;
require 'C:/Users/USER/vendor/autoload.php';
$dotenv = Dotenv\Dotenv::create(__DIR__);
$dotenv->load();
Solution
The reason you're seeing that error is that you only copied the index.php
code, which is not designed to work in isolation. That code has dependencies, one of which being Dotenv
, that needs to be installed using Composer.
In order to get that sample code working you need to download all the code and follow the instructions noted in the php-slim
folder:
- Run
composer install
to install the dependencies - Start the test PHP server locally:
php -S localhost:4242 index.php
- Open http://localhost:4242 in your browser
See also the instructions at the top-level of that repo.
Answered By - Justin Michael
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.