symfony4

Register custom Doctrine type in Symfony4

情到浓时终转凉″ 提交于 2019-12-05 22:48:39
So I have this custom Doctrine type namespace App\Doctrine\Types; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\TextType; class MyType extends TextType { private $prefix=''; public function getName() { return 'my_type'; } public function setPrefix(string $prefix) { $this->prefix=$prefix; } } I registerd in in the config/packages/doctrine.yml: doctrine: dbal: types: my_type: App\Doctrine\Types\MyType Then in Kernel boot() I'm trying to add some parameters to this type: public function boot() { parent::boot(); $myType=Type::getType('my_type'); $myType->setPrefix('abc'); }

MariaDB 10.0 JSON type with symfony 4

僤鯓⒐⒋嵵緔 提交于 2019-12-05 20:59:40
In my Linux server, I have MariaDB version 10.0 which does not support json type (supported until version 10.2) and I can't update it because it is not released in official ubuntu repository. When I run the command doctrine:migration:migrate for creating tables I get a syntax error from MariaDB for json type MariaDB: 10.0.34 - PHP: 7.1 - Symfony: 4.0.6 How do I solve this issue? The problem is that Doctrine is expecting MariaDB 10.2+, but there have been problems getting the latest MariaDB versions into repos (Arch is still at 10.1). The solution is here: https://symfony.com/doc/current

Symfony 4 Doctrine not working from console [2002] No such file or directory

烂漫一生 提交于 2019-12-05 18:32:55
I´m working with symfony 4 and this error ocurr when runnning doctrine console commands: In AbstractMySQLDriver.php line 108: An exception occurred in driver: SQLSTATE[HY000] [2002] No such file or directory I think this is because there´s something wrong with the connection but when I run the application it has access to the database without errors, so I can not imagine what is wrong with the connection. I was able to continue working by creating manually the database and using php bin/console doctrine:schema:create --dump-sql But this is really unwanted because later when the schema needs to

symfony 4 : How to get “/public” from RootDir

霸气de小男生 提交于 2019-12-05 14:43:36
问题 I have an image under the public folder. How can I get my image directory in symfony4 ? In symfony 3, it's equivalent is : $webPath = $this->get('kernel')->getRootDir() . '/../web/'; 回答1: You can use either $webPath = $this->get('kernel')->getProjectDir() . '/public/'; Or the parameter %kernel.project_dir% $container->getParameter('kernel.project_dir') . '/public/'; 回答2: It is a bad practice to inject the whole container , just to access parameters, if you are not in a controller. Just auto

Where do private, custom bundles live in Symfony 4?

早过忘川 提交于 2019-12-05 12:06:40
I have a number of private, custom bundles that I use in my Symfony projects. Under Symfony 3, they lived in a sub-directory of src: src/ DSL/ DSLLibraryBundle/ DSLTelnetBundle/ ... SiteBundle/ # (or AppBundle) Under Symfony 4, the application-specific bundle is gone and it's unclear to me where my custom bundles should live. The documentation on bundles ( https://symfony.com/doc/current/bundles/best_practices.html#bundles-naming-conventions ) provide no specific recommendations for placing custom bundles. I have tried placing my DSL directory directly under the project directory and under src

Symfony 4 login form with security and database users

£可爱£侵袭症+ 提交于 2019-12-05 03:57:10
问题 I was a total noob on Symfony about a week ago and I thought I should just dive in Symfony 4. After a week of trying to solve the basic login problem, I believe the documentation is still missing some parts. Now I've found a solution and I will share it along with some tips on what you might be doing wrong. First part of the answer is a list of suggestions, while the second part is the creation of a project with working login from scratch (supposing you already have composer installed and

How can I override resources for Third-Party bundles in Symfony 4?

浪尽此生 提交于 2019-12-05 03:44:46
I did a fresh Symfony installation by using Symfony Flex and the new skeleton belong to the next Symfony 4 directory structure. Next, I'm going to override some resources like templates, translations, etc. from an external bundle. I've tried to create all these paths for templates (to start) but nothing works: templates/EasyAdminBundle/views/... templates/Resources/EasyAdminBundle/views/... app/Resources/... (just a proof from old structure) Where should I puts my resources files to override third-party bundle resources? For all Symfony versions the resources path is %kernel.root_dir%

Symfony 4, get the root path of the project from a custom class (not a controller class)

▼魔方 西西 提交于 2019-12-05 02:20:26
问题 In the src/Utils directory, I created a custom class Foo for various things. I'm looking for a way to get the absolute root path of the symfony 4 project From a controller, its easy with : $webPath = $this->get('kernel')->getProjectDir(); But from a custom class I created in my src/Utils directory, how can I get the root path directory ? I could pass the path from the controller to the Foo class : $webPath = $this->get('kernel')->getProjectDir(); $faa = new Foo($webPath); $faa->doSomething();

PHPUnit Error: Class not found

被刻印的时光 ゝ 提交于 2019-12-04 18:59:50
I'm using symfony 4.0 and using "symfony/phpunit-bridge": "^4.0" in composer.json. I have installed phpunit-bridge using command composer require --dev phpunit . Now when I run vendor\bin\simple-phpunit tests/Handler It shows this error C:\xampp\htdocs\symfonydemo>vendor\bin\simple-phpunit tests/Handler PHPUnit 6.3.1 by Sebastian Bergmann and contributors. Testing tests/Handler E 1 / 1 (100%) Time: 173 ms, Memory: 4.00MB There was 1 error: 1) App\Tests\Handler\CalculatorResultHandlerTest::testWalkTime Error: Class 'App\Service\CalculateWalk' not found C:\xampp\htdocs\symfonydemo\tests\Handler

How to load, process and use custom parameters from Yaml configuration files in DI Extension class?

五迷三道 提交于 2019-12-04 13:19:40
问题 I'm trying to import a yaml configuration file in my App following the documentation provided here http://symfony.com/doc/current/bundles/extension.html but I always have the error message: There is no extension able to load the configuration for "app" My file is located here : config/packages/app.yaml and has the following structure : app: list: model1: prop1: value1 prop2: value2 model2: ... As this is a simple App, all the files are in src/ . So I have src/DependencyInjection/AppExtension