symfony4

Symfony 4. How to access the service from controller without dependency injection?

只谈情不闲聊 提交于 2019-12-23 04:53:19
问题 I have several services: DieselCaseService, CarloanCaseService LvCaseService. The controller decides which of services to get. $type = $quickCheck["type"]; /** * @var $caseService \App\Service\Cases\CaseInterface */ $type = 'diesel; // for test purposes $caseService = $this->get('case_service.' . $type); The service aliases are declared like this: case_service.diesel: alias: App\Service\Cases\DieselCaseService public: true class DieselCaseService implements CaseInterface { . . . } If I try to

Register custom Doctrine type in Symfony4

自古美人都是妖i 提交于 2019-12-22 09:44:05
问题 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:

Symfony4 Error loading classes custom folder “Expected to find class… but it was not found”

我们两清 提交于 2019-12-21 07:46:05
问题 Problem I'm trying to setup a custom directory structure for some shared classes in my Symfony project. I want to create a custom folder in the root of my project and I want to use the Symfony auto-load feature to automatically register services from that folder. So I added a custom services namespace to the services.yaml file: # src ./config/services.yaml services: ... TestNamespace\: resource: '../TestNamespace/*' ... And I added an empty class in the custom folder: # src ./TestNamespace

Symfony4: Doctrine2 works but no connection in PHPUnit test (kernel booted)

…衆ロ難τιáo~ 提交于 2019-12-19 17:35:30
问题 Strange issue in Symfony4: Doctrine works, I can validate the schema, create the database etc using php bin/console doctrine:schema:create . But my PHPUnit test does not have a connection. By running ./bin/phpunit I get SQLSTATE[HY000] [2002] No such file or directory exception. I followed the steps within the docs regarding booting up the kernel: http://symfony.com/doc/current/testing/doctrine.html My code: class PersistingResultTest extends KernelTestCase { protected $em; protected function

How can I retrieve my environment variables in a parameter file in Symfony4 structure?

此生再无相见时 提交于 2019-12-19 05:58:38
问题 I did a fresh Symfony installation by using Symfony Flex and the new skeleton belong to the next Symfony 4 directory structure. I add and configure a first third-party bundle : HWIOAuthBundle. This bundle is used to connect via Twitter using two secret information. I declare my consumer_id and my consumer_secret in the config/packages/hwi_oauth.yaml file. hwi_oauth: firewall_names: [secured_area] resource_owners: twitter: type: twitter client_id: XXXXXMyIdXXXXX client_secret:

Symfony 4: How to organize folder structure (namely, your business logic)

泪湿孤枕 提交于 2019-12-17 22:30:30
问题 In the Symfony Best Practices is advised to not use bundles to organize business logic. The bundles should be used only when the code in them is meant to be reused as-is in other applications: But a bundle is meant to be something that can be reused as a stand-alone piece of software. If UserBundle cannot be used "as is" in other Symfony apps, then it shouldn't be its own bundle. So, as I'm upgrading my app from Symfony 3.3 to Symfony 4, I think this is the right time to reorganize my code.

mailer symfony 4 not working

梦想与她 提交于 2019-12-17 17:16:58
问题 I started a project using symfony 4 and the mailer doesn't work, however it should be easy. before you ask, if i copy past the login and password from my code i'm able to log into my mail account, also i also tried with a netcourrier mail account, also the 2 way authentification is not active and i allowed less secure app to access the mail account. Here's my conf: in my .env: MAILER_URL=gmail://*******@gmail.com:********@localhost in my controller: public function contact( \Swift_Mailer

Symfony 4 Form file upload field does not show selected filename with Bootstrap 4 theme

萝らか妹 提交于 2019-12-14 02:13:55
问题 Using Symfony 4.2.5, I made a Form with a FileType file upload field as described at upload file. I used the Bootstrap 4 theme as described at form_themes and bootstrap4. config/packages/twig.yaml contains: twig: form_themes: ['bootstrap_4_horizontal_layout.html.twig'] When I load the web page and select a file to upload, the FileType field shows a blank filename: I found this issue was documented in Symfony issue 27477. Is there a way to make the Symfony 4 FileType field show the selected

AppBundle symfony 4

試著忘記壹切 提交于 2019-12-13 22:38:57
问题 I have a problem with Symfony 4 , I want generate entities from an existing database with the command : php bin/console doctrine:mapping:import --force AppBundle xml But an error appears : Bundle "AppBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your App\Kernel.php file? I try to import in the file kernel.php in registerBundles() : new AppBundle/AppBundle(); but undefined class and when I create it in src/AppBundle/AppBundle.php : <

How to install HWIOAuthBundle in Symfony4.3?

回眸只為那壹抹淺笑 提交于 2019-12-13 20:16:14
问题 If i try install this bundle like it described in docs with command composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle i have this error: Problem 1 - Installation request for hwi/oauth-bundle ^0.6.3 -> satisfiable by hwi/oauth-bundle[0.6.3]. - Installation request for php-http/httplug-bundle ^1.16 -> satisfiable by php-http/httplug-bundle[1.16.0]. - php-http/httplug-bundle 1.16.0 requires php-http/client-implementation ^1.0 -> satisfiable by php-http/guzzle6