Pense-bête Symfony2
dans Symfony2Regénérer les assets
php app/console assetic:dump
Mettre à jour les données fixtures sans supprimer les anciennes
php app/console doctrine:fixtures:load --append
Créer les Tables et le Schema
php app/console doctrine:schema:update --force
ou pour voir les requêtes qui vont êtres exécutées
php app/console doctrine:schema:update --dump-sql
Entités
Créer une entité
php app/console generate:doctrine:entity
Mettre à jour les entités (créer getter et setter)
php app/console doctrine:generate:entities App/FrontBundle/Entity/User
Changer le type des entités
php app/console doctrine:mapping:convert --force annotation ./src/
FosUserBundle
Créer des utilisateurs avec fosuserbundle
php app/console fos:user:create
php app/console fos:user:create --super-admin admin user@domaine.com
Changer de rôle pour un user
php app/console fos:user:promote admin
Changer de mot passe d’un user
php app/console fos:user:change-password testuser newp@ssword
Tester les routes
php app/console route:debug
Créer une entité depuis une BD existante
php app/console doctrine:mapping:convert xml ./src/App/FrontBundle/Resources/config/doctrine/metadata/orm --from-database --force
Info sur les mappings doctrine
php app/console doctrine:mapping:info
Mettre à jour les vendors symfony2 avec composer
php ../composer.phar update
Créer un type depuis un form
php app/console generate:doctrine:form AcmeBlogBundle:Post
Créer un bundle
php app/console generate:bundle
Vider le cache
php app/console cache:clear
php app/console cache:clear --env=prod
=> pour optimiser les perfs :
php app/console cache:clear --env=prod --no-debug
Appeler une action/controller depuis la ligne de commande (cron)
http://symfony.com/doc/master/cookbook/console/console_command.html
Définir les droits pour webmaster pour vider le cache
setfacl -R -m u:www-data:rwX -m u:webmaster:rwX app/cache app/logs
setfacl -dR -m u:www-data:rwx -m u:webmaster:rwx app/cache app/logs
BUGS
Erreur :
ContextErrorException: Warning: Erroneous data format for unserializing 'AdminBundle\Entity\User' in /home/monsiteovh/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php line 869
Solution :
/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
public function newInstance() { if ($this->prototype === null) { $this->prototype = @unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name)); if ($this->prototype === false) { $this->prototype = unserialize(sprintf('C:%d:"%s":0:{}', strlen($this->name), $this->name)); } } return clone $this->_prototype; }
—— public function newInstance() { if ($this->prototype === null) { //$this->prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name)); if (PHPVERSIONID === 50429 || PHPVERSIONID === 50513) { $this->prototype = $this->reflClass->newInstanceWithoutConstructor(); } else { $this->prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name)); } }
return clone $this->_prototype;
}
——
Mettre une valeur par défaut à une colonne (Doctrine)
/**
* @var string
*
* @ORM\Column(name="site_statut", type="string", length=10, options = {"default" = "client"})
*/
private $siteStatut;
Bug FOSUserBundle
QuickFix in vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php Line 707
$xmlData = file_get_contents($file);
$xmlElement = simplexml_load_string($xmlData);
Regénérer bootstrap.php.cache
php vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php
Optimiser l'autoloader
composer.phar dump-autoload --optimize
CRUD
php app/console generate:doctrine:crud —entity=AppBundle:Video --format=annotation --with-write --no-interaction
source => http://iabsis.com/fr/community/tuto/first-symfony2-app