impossible to generate bundle - symfony

i'm new to the symfony framework and i'm trying to generate my first bundle ,
i use this command php bin/console generate:bundle but it's not working.
The error message :
There are no commands defined in the "generate" namespace.
You may be looking for a command provided by the SensioGeneratorBundle which is currently not installed.
Try running composer require sensio/generator-bundle.
https://imgur.com/csryfHZ
I've tried to install composer repositories with the command composer require sensio/generator-bundle and nothing has changed

In symfony 4, this bundle is deprecated, you must use the maker-bundle, unfortunately there is no bundle generator available. So you'll need to code your bundle from scratch with the official documentation: https://symfony.com/doc/current/bundles/best_practices.html
By the way, bundle are deprecated and are now only use to share packaged code between projects.
More informations at: https://symfony.com/doc/current/bundles.html

We're not making bundle in Symfony 4.
While it was "good practice" withg Symfony 2, since the new skeleton, it's not the case anymore.
Your default bundle is now App, all your code goes in src/, and all your view (twig files) goes in template/

Related

Fail to create a controller file with make command in Symfony

I'm learning Symfony now and I ran into a problem trying to create a controller file with the make command. The path of the project is "E:\web_dev\testproject". When I ran the command
php bin/console make:controller
and then entered the name of the controller, it returns an error "Failed to create "E:\web_dev\testproject//E:\web_dev\testproject\vendor\composer/../../src/Controller"". What is the problem?
I have the same problem.
I have found this Thread and it seems that the problem is in the Maker Bundle. After running "composer remove maker" and "composer require maker 1.0.2" it works by me.
In the other Thread they used Maker Version 1.0.0 but in Symfony4 the generated AbstactController do not Functionaly so I use Version 1.0.2.
Hope it help you.

PhpStorm doesn't see translations when moved to app/Resources

I had some translations in my bundles, for example in src/Bundle/AppBundle/Resources/translations but when I moved it to app/Resources/AppBundle/translations in my Twig templates it shows that translations are missing. I've tried invalidating cache and restarting the IDE but it didn't help.
How can I fix this?
My PhpStorm version: 2017.2.1.
Symfony Documentation:
"Each time you create a new translation resource (or install a bundle that includes a translation resource), be sure to clear your cache so that Symfony can discover the new translation resources"
Phpstorm may be processing by reading the cache files.
Try clearing the Symfony cache.
bin/console cache:clear
Optimize Composer.
composer install --optimize-autoloader
this issue is fixed in PhpStorm Symfony Plugin via https://github.com/Haehnchen/idea-php-symfony2-plugin/issues/1010

symfony plugin install namespace error

I created a new symfony 2 project using 2.7. When I try to install a plugin using command line "symfony plugin:install sfFormExtraPlugin", I got an error:
"[InvalidArgumentException]
There are no commands defined in the "plugin" namespace.".
When I type "symfony list", I got "
Available commands:
about Symfony Installer Help.
demo Creates a demo Symfony project.
help Displays help for a command
list Lists commands
new Creates a new Symfony project.
self-update Update the installer to the latest version.
selfupdate Update the installer to the latest version.
". no plugin or other command like "cache" etc. What should I do? Thanks!
sfFormExtraPlugin is a plugin for Symfony 1 and won’t work with Symfony 2.*
Also, the symfony command line tool in Symfony 2 is not meant for application commands anymore but for creating new projects/installing Symfony. The new command line tool for application commands is app/console (which you use like php app/console something:something.)
But even then, this command isn’t used for managing dependencies (like plugins) anymore. We use composer for that instead. That’s a powerful package manager for PHP that can install and update the packages you require and also make sure that they are compatible. And it is not limited to the Symfony world.

composer install does not update psr4 autoloader

I am using composer with a symfony project which require sonata-project/sonata-doctrine-orm-bundle and its dependencies (naturally with many other dependencies).
When I update symfony 2.3.6 to 2.5.5 and my vendors turn by turn, it updates sonata doctrine orm bundle which was written using PSR-0 autoloader and now uses PSR-4.
When composer finished to update all vendors and the symfony console command cache:clear run I get an error like class Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle can not be found.
When I look around to check what could be wrong, I discovered that the file vendor/composer/autoload_psr4.php is not updated with the path. The composer.json of sonata doctrine orm admin bundle is compliant with the paths I found in my vendor directory.
Does anyone have had the same or similar issue ? I can't find anything interesting about this...
Try to update composer, this was the issue I had when having problems with PSR-4 autoloading

How do you register bundles in Symfony2.1 designed for older versions of Symfony?

I am attempting to use they EntityAudit extension for Doctrine2 in my Symfony2.1 app.
I'm very new to this, and I've just started realizing how many "correct" methods there have been for installing new bundles for Symfony over the years. Some sort of "Deps" file used to exist but does no longer? When installing Symfony, "using Composer" was an option -- but purely an option, it seemed. Now I'm starting to think that's not true.
In EntityAudit's instructions it refers to "Autoload", and based on other things, I'm apparently supposed to modify the registerNamespaces array in my Autoload.php. Except I don't have that. So I found this link where the guy indicates Symfony2.1 doesn't do that anymore in favor of using Composer.
I don't really know how to use Composer in this case though. I don't really know how to use it at all, actually, but I seem to have bumbled through doing 1 or 2 basic things in it -- "updating" itself and "installing" .. vendors? Anyway, I can find no instructions general enough to be adapted for this need. Thanks in advance for any help!
The deps file is used in 2.0 to manage dependencies. The 2.1 version uses the much better Composer dependency management tool.
Install with composer
First you'll need some basix about composer. For instance, read this article: http://net.tutsplus.com/tutorials/php/easy-package-management-with-composer/
Before you can use composer to install a bundle you should look for a Packagist package of that bundle. For the SimpleThings\EntityAuditBundle you should look for a simplethings/entity-audit-bundle package and it does exists: https://packagist.org/packages/simplethings/entity-audit-bundle
SIDENOTE
Packagist is the main archive for Composer.
If you are searching for a bundle, the best thing you can do is check out
KnpBundles, it is the unofficial achive of Symfony Bundles.
If a bundle contains a README file, it is displayed there and if it has a Packagist
package it shows a link to the package. It's a really usefull site to begin searching
for bundles.
Now you have the package name, you should determine the version you want to use. As this is a not-finished bundle we can use the latest version by using the dev-master version. But it could be possible that a dev-master version is for Symfony2.2 and we should use another version if we use Symfony2.1, this should be in the README file (in the Package, which you can view on Github or KnpBundles). If it isn't in the README, you can use the version you want. An example of the note about version can be found in the StofDoctrineExtensionsBundle.
Now we can add the bundle to our composer.json file and update the dependencies. You can do this manually:
Add it to the composer.json file:
{
...,
"require": {
...,
"simplethings/entity-audit-bundle": "dev-master"
}
}
Update the dependency
$ php composer.phar update simplethings/entity-audit-bundle
or update all dependencies
$ php composer.phar update
Or you can do this is one command:
Run this command (which includes the package in the composer.json and updates the package)
$ php composer.phar require simplethings/entity-audit-bundle:dev-master
Now the bundle is installed into our Symfony project (in vendor/simpletings/) and the autoloader recognises this bundle. The only thing we need to do now is registering the bundle in the AppKernel:
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
// ...
public function registerBundles()
{
$bundles = array(
...,
new SimpleThings\EntityAudit\SimpleThingsEntityAuditBundle(),
);
// ...
}
}

Resources