Cache
php app/console cache:clear
php app/console cache:clear --env=prod
Cronjobs
Will execute cron job in production environement
php app/console --env=prod exec:cronjobname
Assets
php app/console assets:install web
Bundles and Entities
Generate a Bundle:
php app/console generate:bundle
Generate Entity Client:
php app/console doctrine:generate:entity --entity="AcmeDemoBundle:Client"
Then print the sql query without executing it:
php app/console doctrine:schema:update --dump-sql
And finally force the update and execute it
php app/console doctrine:schema:update --force
Generate Entities FROM DATABASE
When tables exists in your database you can generate Entity and ORM xml files with these commands:
1. Import to generate xml metadata files:
php app/console doctrine:mapping:import AcmeDummyBundle xml
Once metadata files are generated change xml file name to ClicDAO.orm.xml AND entity name to ClicDAO, then set repository file name like this
- change field names to your convenience and then
2. Generate Entities (Getters/Setters):
php app/console doctrine:generate:entities AcmeContactBundle
Convert Mapping entities to XML (Metadata files: /Resources/config/doctrine/<entity_name>.xml)
If your entities are already created and you want to convert to xml file:
php app/console doctrine:mapping:convert xml
php app/console doctrine:mapping:convert xml ./src/Acme/CommandeBundle/Resources/config/doctrine --from-database --force
Cache Clear solve persmission errors
php app/console cache:clear --no-warmup
Install Doctrine fixtures
Add this line in composer.json
"doctrine/doctrine-fixtures-bundle": "dev-master",
Then run
php composer.phar update --prefer-source
then register bundle in your appKernel: new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
Load fixtures
\project_new\src\Acme\UserBundle\DataFixtures\ORM\LoadUserData.php
php app/console doctrine:fixtures:load --append //(will add data to existant)
Add data from a Bundle only:
php app/console doctrine:fixtures:load --fixtures=C:/xampp/htdocs/project_new/src/Acme/UtilBundle/DataFixtures/ORM/ --append
Routing
Verify routing:
php app/console router:debug
Cache problem on server
Problem: RuntimeException: Failed to write cache file "/var/www/Symfony/app/cache/dev/classes.php".
A force brute solution:
rm -rf app/cache/*
rm -rf app/logs/*
PHP-CS Fixer
PSR code formatting tools:
php c:/xampp/php/php-cs-fixer.phar fix c:/xampp/htdocs/project_new/src/Acme/SendingBundle/Model/Sending.php --verbose --level=psr2
Test PhpUnit
* Do not write unit tests for a Controller
# specify the configuration directory on the command line
phpunit -c app/
# run all tests in the Utility directory
$ phpunit -c app src/Acme/DemoBundle/Tests/Utility/
# run tests for the Calculator class
$ phpunit -c app src/Acme/DemoBundle/Tests/Utility/CalculatorTest.php
# run all tests for the entire Bundle
$ phpunit -c app src/Acme/DemoBundle/
Composer Optimize Autoload
php composer.phar dump-autoload --optimize
Install only a bundle, it should be added into the file composer.json first:
php -d composer.phar update codeplex/phpexcel