I'm trying to make my website live but keep getting the same error...I've tried looking everywhere and using everyone solution with no luck.
Error
ClassNotFoundException: Attempted to load class "DestinationAppBundle" from namespace "Destination\AppBundle" in /home/dcms/public/html/dcms/apha/app/AppKernel.php line 19. Do you need to "use" it from another namespace?
AppKernel.php
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Destination\AppBundle\DestinationAppBundle(),
new Destination\Auth\HashInterfaceBundle\DestinationHashInterfaceBundle(),
);
File Structure
src
Destination
AppBundle
Any ideas?
first: check if the file src\Destination\AppBundle\DestinationAppBundle.php does exist
second: open DestinationAppBundle.php and chek if the namespace is Destination\AppBundle
third: check if the classname declaration is the same as the filename (in your case : DestinationAppBundle)
Update composer.json like this:
"psr-4": {
"AppBundle\\": "src/AppBundle",
"UserBundle\\": "src/UserBundle"
},
After edit composer.json YOU MUST RUN composer dump-autoload
Verify in AppKernel.php the use of this class DestinationAppBundle
And the namespace in the class DestinationAppBundle
What is the namespace in your DestinationAppBundle.php ?
It should be :
<?php
namespace Destination\AppBundle;
If you are sure the namespace and service definition are right you can try:
Upgrade Symfony version. I had an strange issue with Symfony 2.8.11, new services added gave me a ClassNotFoundException. Upgrading to 2.8.17 solved it.
Try remove app/cache/* contents
Check if you are using a pre-generated boostrap cached file without the "--no-dev" option (composer dump-autoload --optimize --no-dev --classmap-authoritative) and launch command again.
Symfony uses PSR autoload.
You need to configure autoload in the composer.json file:
"autoload": {
"psr-4": {
"": "src/"
},
This will include all files and folders under the \src folder
Related
i have maybe primitive problem. I created my first package in composer. It is just one class in one namespace.
composer.json:
...
"autoload": {
"psr-4": {
"UrlParser\\": "src/"
}
},
...
and i have this in: src/UrlParser/url.php
<?php
namespace UrlParser;
class Url{
...
everything is OK, i uploaded my package into composer. I install it into my project, but when i call this:
<?php
require_once 'vendor/autoload.php';
$a = new UrlParser\Url("http://localhost/aaa.html");
i get this: Fatal error: Class 'UrlParser\Url' not found in C:\xampp\htdocs\ccc\01\index.php on line 3
I am new in composer and i try to google my problem, but i am lost :)
Thanks
Try this
namespace UrlParser;
$a = new Url("http://localhost/aaa.html");
If it doesn't work, there's probably a problem with autoload that you didn't get the right way
the problem was, that i didnĀ“t do this:
composer dump-autoload -o
I want to use the tFPDF class and load it with composer-autoload. Since I could not find an official tFPDF composer repo, I simply downloaded the zip file and extracted it in the folder vendor/tfpdf.
Next I added the psr-4 to the composer.json file:
"autoload": {
"psr-4": {
"App\\": "app/",
"tFPDF\\": "vendor/tFPDF"
},
I also added in the tfpdf.php the namespace
<?php
namespace tFPDF;
define('tFPDF_VERSION','1.25');
class tFPDF
{
Finally I produced a new autoload file:
composer dump-autoload
When I now try to create a PDF like this:
$pdf = new \tFPDF\tfpdf();
$pdf->AddPage();
// Add a Unicode font (uses UTF-8)
$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
Then the last line will rise an error:
Cannot access private property tFPDF\TTFontFile::$charWidths
Why is that and how can I fix it?
There is now a package https://github.com/Setasign/tfpdf (released in September 2018, a couple of month after the question was asked here)
Install with composer like this:
composer require setasign/tfpdf
you can either use it like this:
namespace your\namespace;
class Document extends \tFPDF
or like this:
$pdf = new \tFPDF();
We're working with Sylius and trying to create new bundles. Through the console using php bin/console generate:bundle a new bundle is easily createable. however when we try to run the site we get the error: ClassNotFoundException in AppKernel.php line 36: We are registering our new bundle in the AppKernel.php file, and editing the composer.json file to autoload the new bundle but nothing seems to work. We have tried every solution mentioned on SO without luck. Can anyone point us in the right direction?
MUCH APPRECIATED-!
public function registerBundles()
{
$bundles = [
new \Sylius\Bundle\AdminBundle\SyliusAdminBundle(),
new \Sylius\Bundle\ShopBundle\SyliusShopBundle(),
new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle(),
new \FOS\OAuthServerBundle\FOSOAuthServerBundle(), // Required by SyliusApiBundle
new \Sylius\Bundle\ApiBundle\SyliusApiBundle(),
new \AppBundle\AppBundle(),
//NEW BUNDLE
new TGB\AmazonBundle\AmazonBundle(),
];
return array_merge(parent::registerBundles(), $bundles);
}
from our composer.json file
"autoload": {
"psr-4": {
"AppBundle\\": "src/AppBundle/",
"TGB\\AmazonBundle\\": "src/TGB/AmazonBundle/"
},
"classmap": ["app/AppKernel.php", "app/AppCache.php"]
},
Found the answer, we needed to run composer dump-autoload it was caching and wouldn't go look for the new classes that it needed to load.
I try to autoload my custom pdo class with composer.
Ran the following command to update autoload:
compser update
composer install
Both seem to work, no error prompted. But,
vendor/composer/autoload_namespaces.php
Does not list the custom namespace added to composer.js.
File structure
-Root
->classes
->pdo
->class.php
->vendor
->various extensions loaded with composer
index.php
PHP Class
namespace Classes\Pdo;
Class DB {
//Do some stuff...
}
Composer.js
"autoload": {
"psr-4": {
"Classes\\Pdo\\": "classes/pdo"
}
}
Index.php
$pdo = new \Classes\Pdo\DB(); //Fatal error: Class 'Classes\Pdo\DB' not found
Old question, but I just ran across this myself.
For future Googlers, in my case the issue turned out to be the name of the class file did not exactly match the class name.
See this post: Why does 'composer dumpautoload -o' fix 'Class not found' PHP error?
My Internet conexion is useless to install a symphony 2 dependency with composer as far as I can say. Is there a way to install a third party bundle manually? I have been looking in Google and I did not find any useful thing so far. About my connection issue, I started this thread to try and find a solution to install within this connection. here I am trying to find clues to a solution to install manually.
Regards
1 Create under vendor directory the path for bundle :
/*like mycompany*/ /*like product-bundle*/ /*like MyCompany*/
vendor/yourbundlenamespace/your-bundle-name-bundle/YourBundleNameSpace/
2 Go to in the new path and put the content of budle (or clone from github).
3* #deprecated
Load the reference path on autoload, so go to in
vendor/composer/autoload_namespaces.php
and put in the array
'YourBundleNameSpace\\YourBundleNameBundle' => array($vendorDir . '/yourbundlenamespace/your-bundle-name-bundle');
4 Register bundle: go to in
app/AppKernel.php
and put in the array $bundles the new bundle:
```
public function registerBundles()
{
$bundles = array(
//...
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
//...
// this is our bundle :)
$bundles[] = new YourBundleNameSpace\YourBundleNameBundle\YourBundleNameBundle();
}
```
UPDATE
Point 3: this method is not performance because when update via composer is overwrite, instead, you should do:
-go to on app/autoload.php
and put following code after $loader definition
```
//add customs classes
$loader->add('YourBundleNameSpace\\YourBundleNameBundle','vendor//yourbundlenamespace/your-bundle-name-bundle');
```