I'm try to install Sonata ClassificationBundle on my project in symfony 3.4.
But i can't install it correctly, i thinks i have missing something.
I have pass all step but my application display this message:
Attempted to load class "ApplicationSonataClassificationBundle" from namespace "Application\Sonata\ClassificationBundle".
Did you forget a "use" statement for another namespace?
I have try to add class to autoload with
"psr-4": {
...
"Application\\Sonata\\ClassificationBundle": "src/Application/Sonata/ClassificationBundle",
"Application\\": "/src/Application"
},
Without result same error.
My class was perfectly generate.
How can i do ?
Thanks
Sonata ClassificationBundle Documentation
no need for an extra PSR-4 entry.
Application\\ -> src/Application
is enough, but you should remove the leading / before src.
Related
So I've been asked to create a new project in Laravel (5.4). The project will need to load in a "platform" which is also built in Laravel 5.4 and contains already written controllers and models.
I am currently autoloading the platform in composer as so :
"psr-4": {
"App\\": "app/",
"Frontend\\": "app/Modules/Frontend/",
"Admin\\": "app/Modules/Admin/",
"Platform\\": "../platform/Modules/"
}
I have a routes file with the following in it :
Route::get('/', 'HomeController#index')->name('home');
Then inside of my HomeController, I'm trying to load the platforms' HomeController.
use Platform\Modules\Frontend\Controllers\HomeController as HC;
I am then presented with the error
Class 'Platform\Modules\Frontend\Controllers\HomeController' not found
Is this at all possible to do, wise to do? I'm open to any form of suggestions.
I have managed to mimic your situation in 2 PHP hello world projects.
The problem here is that your 2 projects are using the same namespace App and when you try to autoload the 2nd project into the namespace Platform, you get Class not found error. This is because your PSR-4 namespace for Platform doesn't correspond the namespace in your 2nd project.
App\Modules\Frontend\Controllers is never Platform\Modules\Frontend\Controllers. Those are totally 2 different namespaces.
Hopefully, there's a solution for this by providing an array of paths to the common namespace in both projects.
"psr-4": {
"App\\": ["app/", "../platform/Modules/"],
"Frontend\\": "app/Modules/Frontend/",
"Admin\\": "app/Modules/Admin/"
}
In your HomeController, load your controller like this:
use App\Modules\Frontend\Controllers as HC;
Always double check running the command below if you get Class not found error:
composer dump-autoload
I'm searching for override a file which is in the vendor's directory
but is not a bundle.
I'm working with Symfony 2.7
To be more specific, i'm trying to override a method in this file :
vendor/akeneo/pim-community-dev/src/Pim/Component/Catalog/Updater/ProductUpdater.php
And I'd like to do it in a file like :
src/MyApp/Component/Catalog/Updater/ProductUpdater.php
All the documentation I've found is relied to parts of a Bundle.
So, is it even possible to do that ?
If it is, how to do it ?
There is a way to override a file using composer.
You can add in your composer.json under the autoload->psr-4 key something like this.
"autoload": {
"psr-4": {
"Pim\\Component\\Catalog\\Updater\\": "MyApp/Pim/Component/Catalog/Updater"
},
Where the first part is the namespace of the file you want to override and the second part is the new path.
This can create some issues when you add new packages to composer, so make sure you run composer dump-autoload to recreated the autoload order.
i don't really like this method, but it did save me a couple of times to fix files from bundles without actually forking the bundle, and if nothing else helps this can me used as a last resort.
More about composer autoload here
https://getcomposer.org/doc/01-basic-usage.md#autoloading
Hope this helps,
Alexandru Cosoi
I'm working with ZendFramework3 for a project. I have a module that works
(for example : myProject/module/MyModule). Everything it's working but I would like to extends the controller which is in MyModule/src/Controller/CrudController. I mean, I have a simple module in my ZF3 project and I want the controller in this module to extends a Controller in a framework placed in myProject/vender/MyFramework/Mvc/Controller/
Problem is Fatal error: Class 'MyFramework\Mvc\Controller\ExtendedController' not found in C:\wamp\www\myProject\module\MyModule\src\Controller\MyController.php on line 7
<?php
namespace MyModule\Controller;
use MyFramework\Mvc\Controller\ExtendedController;
class MyController extends ExtendedController
{
}
I don't know what am I supposed to do to find the Controller placed in a framework in the vendor directory.
If someone could help me on this, it would be a pleasure.
Currently, I based my code on what Zend does. For example, we could find this
use Zend\Mvc\Controller\AbstractActionController;
I think the controller 'MyController' which extends the ExtendedController finds the right file but the controller is probably not load or something like that
Yours -)
EDIT : My problem has been resolved. The problem was the composer.json which needed to be updated.
I added this code in composer.json file :
"autoload" : {
"psr-0" : { "MyFramework\\": "vendor/MyFramework/{folder}/"},
},
It looks like your module is not found by composer. Have a look at the composer.json file from zend-mvc, especially the autoload section. That's how composer knows how to register packages.
AFAIK you can't just place a package in the vendor dir. You need to create a complete composer package and add it to your composer.json require section.
What might be easier during development is placing your module inside the ./module/ dir. You can than edit your module and when it's ready you publish it via packagist or a private composer repository.
To get this working you need to add MyFramework to the autoload section of your project:
"autoload": {
"psr-4": {
"Application\\": "module/Application/src/",
"MyFramework\\": "module/MyFramework/src/"
}
},
Obviously, you need to update the autoloader with composer dump-autoload after changing the autoload section.
There is a vendor that I want to use that was originally created for Symphony and it isn't namespaced into Laravel, I'm not too sure on how to make it work.
Here is the package: https://github.com/caponica/AmazonMwsComplete
I read somewhere that I would have to add psr-0 into composer and I already have the psr-4 default data in composer so I added:
"psr-0": {
"MWS\\": "caponica/amazon-mws-complete"
},
The MWS\\ I just made up since I wasn't too sure what to do and the other portion is the vendor folders, figured that's what I needed.
So, when I tried to call the class into routes for testing I tried:
use MWS\CaponicaAmazonMwsComplete\AmazonClient\MwsProductClient;
and it keeps saying that the MwsProductClient class isn't found.
It happened because you are trying to use wrong path and namespace. Accrording to the source code of package you are trying to use the namespace you want to load is namespace CaponicaAmazonMwsComplete\AmazonClient;
So you need to include this into you composer.json file:
"psr-0": {
"CaponicaAmazonMwsComplete\\": "caponica/amazon-mws-complete/src"
},
I'm not 100% sure but it should work. Don't forget to run composer dump-autoload before using.
If it doesn't work add a comment here and I will check it again.
UPDATE:
So I managed it to work using PSR-4 autoload:
"psr-4": {
"App\\": "app/",
"CaponicaAmazonMwsComplete\\": "vendor/caponica/amazon-mws-complete/src/CaponicaAmazonMwsComplete",
"AmazonPhpClientLibrary\\": "vendor/caponica/amazon-mws-complete/src/AmazonPhpClientLibrary"
}
But note that this library is quite outdated and it's documentation doesn't fits it's code.
I searched for hours to solve my problem, but now I just don't know what to check anymore..
I created a new project for composer: https://github.com/Gcob/esvit-ng-table-for-symfony
Everything is fine until it comes to the appKernel.php, I declarate my new freshly downloaded from composer bundle like this: new Gcob\NgTableBundle\GcobNgTableBundle(), but I got an error message:
ClassNotFoundException in AppKernel.php line 23:
Attempted to load class "GcobNgTableBundle" from namespace "Gcob\NgTableBundle".
Did you forget a "use" statement for another namespace?
I don't know exacly how the appKernel finds its bundles, but I know that the namespace is important and the filename too, so my file GcobNgTableBundle.php has the namespace namespace Gcob\NgTableBundle; and the class declaration is class GcobNgTableBundle extends Bundle as it should be.
Is there any place I should tell the kernel that the file GcobNgTableBundle.php exists for vendor bundles? If some one got any idea, please tell me, but don't forget that I tried a lot of stuff ( first time asking question o_O )
You need to change your composer and add an autoload part.
Without it, namespaces can fail. Check documentation for details.
It must be similar to this:
"autoload": {
"psr-4": { "Symfony\\Bundle\\EsvitNgTableBundle\\": "" }
},
Check this one for example.
After a lot of wasted time, I understood :P The answer of mim was in the good direction! I learned here how composer namespaces works. The appKernel in Symfony only loads the composer file "vendor/composer/autoload_namespaces.php" to load FAKE namespaces xD.