0
I am unable to instantiate the object, my class inside the source/Models folder
<?php
namespace Source\Models;
use CoffeeCode\DataLayer\DataLayer;
class Post extends DataLayer
{
public function __construct()
{
parent::__construct("post",["title","description"]);
}
}
My generate.php that is in the root folder
<?php
require __DIR__ . "/vendor/autoload.php";
use Source\Models\Post;
use Faker\Provider\Image;
use Faker\Provider\Lorem;
for ($i=0; $i < 1; $i++) {
$post = New Post;
$post->title = lorem::text(80);
$post->cover = Image::image("/images", 300, 150);
$post->description = Lorem::paragraph(2,true);
var_dump($post);
}
my file . json
{
"name": "rtsgo/blog",
"description": "blog com pagina\u0000\u0000o",
"require": {
"fzaninotto/faker": "^1.9",
"coffeecode/datalayer": "^1.1",
"coffeecode/paginator":"^1.0"
},
"authors": [
{
"name": "Renan Teotonio",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": {
"Source\\":"source/"
},
"files": [
"source/Config.php"
]
}
}
my folder structure
I’m using PHP 8, but always gives error
Fatal error: Uncaught Error: Class "Source Models Post" not found in C: xampp htdocs BLOG generate.php:11 Stack trace: #0 {main} thrown in C: xampp htdocs BLOG generate.php on line 11
The class Post is not being loaded before use
– Valdeir Psr
Important to improve your question by clicking [Edit]. Which folder this class comes from
Post
? Using an autoload? Poser? Provide a [mcve]– Wallace Maxters
Spun
composer dump
?– Wallace Maxters
how can I carry the Class before?
– Renan Teotonio