creating bundle in symfony in terminal - php

i want to create a bundle in my symfony project via
php bin/console generate:bundle
but it errors me in the terminal:
[Symfony\Component\Config\Exception\FileLoaderLoadException] The file
"../../src/AppBundle" does not exist (in:
C:\wamp64\www\exp\app/config) in
C:\wamp64\www\exp\app/config\services.yml (which is being imported
from "C:\wam p64\www\exp\app/config\config.yml").
[Symfony\Component\Config\Exception\FileLocatorFileNotFoundException]
The file "../../src/AppBundle" does not exist (in:
C:\wamp64\www\exp\app/config).

You might have deleted AppBundle from src folder (or test folder) manually which is the major reason for getting this error.
Browse app\config\config.yml , app\AppKernel.php and app\config\routing.yml and remove the referring to AppBundle.
Once done Please clear the cache and re-run the project.

Related

Laravel home page is not displaying correctly

I have my laravel project installed using homestead and I connect to it via SSH using Vagrant(on Windows). The first time I launched my project there was a message indicating i have an error in my public/index.php file indicating that directory specified in 'require' on 14 line is not found it was written like this
require __DIR__.'/../vendor/autoload.php';
then I just replaced this line of code with directory of welcome.blade.php file (require .../welcome.blade.php) (the home page of Laravel) and this page displayed each time I went to my project website but there was another message displayed saying
Illuminate\Foundation\Application' not found in
/home/vagrant/code/myProject/bootstrap/app.php on line 14.
I think that is because of the laravel version installed enter image description here
What I find quite suspicious is that I haven't got env file and vendor folder inside my project folder. vendor folder was located in AppData/Roaming/Composer folder by default. I just moved that folder to my project folder
First thing, Revert the changes within public/index.php back to how it was. That deals with autoloading and bootstrapping the laravel application and should never really be changed.
Now ssh to your vagrant box and within the laravel project, run cp .env.example .env and then edit the newly copied .env file to have all your details for DATABASE and APP_NAME.
Next, go into your project, and run composer install and this will install all the needed dependencies from the composer.json file.
And lastly, from within your project, you should now run php artisan key:generate to generate the APP_KEY.
This should fix your issue.
I would also advice that you look carefully over the documentation at https://laravel.com/docs

Symfony3 - creating a vendor-based bundle

We'd like to create a bundle which can deployed via composer/packagist for others to use. It'll wrap the logic created by the owners of MessageBird. Basically a kind of Service which will indeed be called with the container via ourvendor.messagebird.messaging.
Since it's a type of bundle (as per the docs of Sf3), we created a bundle while following the documentation:
http://symfony.com/doc/current/bundles/SensioGeneratorBundle/commands/generate_bundle.html
As the directory /src we used /vendor instead. That's when it all went wrong. Our namespace could not be located, loaded or even when we manually added it to the autoloading classes of Composer it failed all the same.
The question is, what is the best practice to go about this? We got it working right now and what we did was the following:
We created a bundle wit the following cmd:
bin/console generate:bundle --shared --namespace=OurVendor/MessageBird/MessageBirdBundle --bundle-name=MessageBirdBundle --format=yml
We moved the /src/OurVendor directory to /vendor/OurVendor as the only way to get a perfect generation was to use the default /src folder.
We manually updated the AppKernel.php
We did some debugging with namespaces for Composer but eventually we added "OurVendor\\":"vendor/" to the "autoload/psr-4" directive in root composer.json
We ran composer dumpautoload && bin/console cache:clear -e dev which resulted in an error.
We ran composer -o update which checked all dependencies and updated accordingly, including autogenerated autoload files
Strangely enough we had to add the Bundle to the AppKernel.php class and cleaned the cache again.
After all this it worked but the documentation said no such thing about developing a 3rd party vendor bundle.
http://symfony.com/doc/current/bundles/best_practices.html
So long story short, did we go about it the wrong way or what?
/vendor directory is managed by composer. Do not copy/move anything there. Don't even edit anything there, unless you understand all consequences.
When you create a shared bundle, you need to push it to a VCS of your choice, and add it as a dependency in composer.json of the project which uses it.
When you run composer update it will check-out your bundle into /vendor directory and generate correct autoload file.
Please read more how to use private repositories with composer.

Symfony cache clear command not working but no cache by the way

I run the command
php app\console cache:clear
And get the fowllowing answer in a local environnement in Windows
[Symfony\Component\Filesystem\Exception\IOException]
Failed to remove directory "D:\nginx\web\symfony\dev\var\cache\de~\annotations\fd"
I first checked if the weird de~ folder existed and deleted it running :
mkdir empty
c:\Windows\System32\Robocopy.exe /MIR empty cache *
which by the way works also to delete too long file names in the cache folder.
Then I checked in windows ui the cache folders, I had a previous cache folder in the app directory and now that I updated Symfony using composer (v2.8.7), it appears to be in the var folder.
All those cache folders are empty, but I still get the weird message with that de~ folder that does not exist anymore.
I know I worked with annotations to improve my entities to create a postgresql database and tables with correct behavior and modified my config file to use entity managers to have more control over which tables tables to create but I don't know if that error comes from there as I use Doctrine annotations in these entities files.
Try adding the --no-warmup flag to the cache clear command:
$ php app\console cache:clear --no-warmup
This has negated strange cache errors for me in the past. Otherwise some wrong permissions are probably being set somewhere.

Generating Bundle in Symfony

Can't find a solution for this on stack.
I'm using ubuntu server,
$php app/console generate:bundle --namespace=WMDN/FirstBundle --format=yml
goes fine until :
Generating the bundle code: OK
Checking that the bundle is autoloaded: FAILED
Confirm automatic update of your Kernel [yes]? yes
Enabling the bundle inside the Kernel: OK
Confirm automatic update of the Routing [yes]? yes
Importing the bundle routing resource: OK
The command was not able to configure everything automatically.
You must do the following changes manually.
- Edit the composer.json file and register the bundle
namespace in the "autoload" section:
I thought it was permissions, and set the whole dir to 775 and made sure owner was good.
I thought it was outdated bug for symfony and deleted whole dir, and got 2.4.4
I'm following a tutorial and their bundle generates just fine and I'd like mine to do it as well.
Why can it not autoload? My Namespace should be good to use. I cannot figure it out.
I have composer installed.
Following this tutorial series : http://www.youtube.com/watch?v=GIcY5YYfZ14 and I'd really like to get my first bundle created so I may continue.
In conclusion, what are the reasons a bundle would fail autoload?
Per to comments, solution was to set the --src parameter correctly.

Symfony 2 - How to delete a bundle?

So my question is how to delete bundle I created?
You create bundles with this console command:
php app/console generate:bundle --namespace=Test/BlogBundle --format=yml
And thats awsome but what if I need to delete this bundle?
Is there a console command to delete a bundle I dont need any more?
I know that when you create new bundle from console, you:
1. create /src/Test/BlogBundle directory
2. change /app/config/routing.yml file to include routes
3. include your new bundle in /app/Resources/App.Kernel.php
4. I think there is something changed in /app/cache/...
Now what would be correct way of deleting a bundle completely?
Its joust that using console these bundles are generated "magically" so I dont know what did this command changed in folder structure and files?
It is basically the process you have outlined, only in somewhat different order.
delete /src/Test/BlogBundle directory
change /app/config/routing.yml file to remove the bundle routes
remove your new bundle from /app/AppKernel.php
clear cache (either by deleting cache/{$env} or console cache:clear)
If this wasn't installed using a dependency manager - that should be all.
I know I am late to answer this but Symfony has instructions on how to delete the bundle. This is how I delete. You can use the same instructions for other bundles you created and want to remove now.
To delete a bundle in Symfony 3 (and higher) :
Method 1 :
go to composer.json, search & delete the bundle.
run composer update ( it will automatically remove the bundle and clear the cache)
Method 2 :
run composer remove alias/to/your/bundle
f.e : composer remove nesbot/carbon
That's all.

Categories