symfony

Get the route name in a Symfony service [duplicate]

和自甴很熟 提交于 2020-12-13 03:45:07
问题 This question already has answers here : Getting the route name inside a service in symfony (2 answers) Closed 2 years ago . Im try to get the name of the current route in a Symfony 4 service. routes.yaml test-route: path: /test controller: App\Controller\Test::test service class Myservice { private $u; public function __construct(Utilities $u){ $this->u = $u; $route = getRouteSomehow(); // should return "test-route" } } I found this piece of code to grab the route: $requestStack-

Symfony NotBlank constraint allow blank string

安稳与你 提交于 2020-12-13 03:22:26
问题 I'm working with Symfony5 and ApiPlatform with phpunit for the tests I'm running tests on field validation. My issue comes from the fact that I want to restrain the user's possiblity to enter a blank string in a property named name as follow : /** * @ApiResource( * attributes={ * "normalization_context"={"groups"={"cons:read", "cons:list"}}, * "denormalization_context"={"groups"={"cons:write"}} * }, * collectionOperations={ * "get"={ * "mehtod"="GET", * "normalization_context"={"groups"={

Symfony NotBlank constraint allow blank string

冷暖自知 提交于 2020-12-13 03:22:10
问题 I'm working with Symfony5 and ApiPlatform with phpunit for the tests I'm running tests on field validation. My issue comes from the fact that I want to restrain the user's possiblity to enter a blank string in a property named name as follow : /** * @ApiResource( * attributes={ * "normalization_context"={"groups"={"cons:read", "cons:list"}}, * "denormalization_context"={"groups"={"cons:write"}} * }, * collectionOperations={ * "get"={ * "mehtod"="GET", * "normalization_context"={"groups"={

Symfony NotBlank constraint allow blank string

荒凉一梦 提交于 2020-12-13 03:20:29
问题 I'm working with Symfony5 and ApiPlatform with phpunit for the tests I'm running tests on field validation. My issue comes from the fact that I want to restrain the user's possiblity to enter a blank string in a property named name as follow : /** * @ApiResource( * attributes={ * "normalization_context"={"groups"={"cons:read", "cons:list"}}, * "denormalization_context"={"groups"={"cons:write"}} * }, * collectionOperations={ * "get"={ * "mehtod"="GET", * "normalization_context"={"groups"={

Failed to reload nginx.service: Interactive authentication required

放肆的年华 提交于 2020-12-12 05:43:32
问题 I am working on project using symfony 3, the project run on nginx server and i am trying to reload the configuration files with the following command: "systemctl reload nginx" from the controller. /** * @Route("/testReloadConfig") */ public function testReloadConfigAction(Request $request){ $output = []; $result = null; $cmd = 'systemctl reload nginx 2>&1'; exec($cmd, $output, $result); return new JsonResponse([ 'result' => $result, 'output' => $output, ]); } The response: {"result":1,"output

Running Symfony 5 with reverse proxy in subdirectory

只愿长相守 提交于 2020-12-10 14:00:30
问题 I like to run a Symfony 5 application behind a reverse proxy which supplies the following endpoint: https://my.domain/service1/ The proxy config basically is this: ProxyPass /marketsy/ http://internal.service1/ On the server the reverse proxy is connecting to, I use the following apache rule for serving my Symfony application: <VirtualHost *:80> ServerName internal.service1 DocumentRoot /webroot/service1/public <FilesMatch \.php$> SetHandler proxy:unix:/run/php/php7.2-fpm-ui.sock|fcgi:/

Symfony 4 multiple entities in single form

泪湿孤枕 提交于 2020-12-08 12:44:40
问题 Been trying for hours and hours to get my multi entity form to work, but it really breaks my head and none of the examples I've found work. I checked the Collection form type documentation and form collections, as well as the Entity form type. I have a User entity, UserRole entity and a Role entity. UserRole contains a userID and a roleID. Just a linking table. The form shows fields to create a User and I want to be able to as well select a new Role for the new user. So I've tried to use the

Symfony 4 multiple entities in single form

余生长醉 提交于 2020-12-08 12:38:51
问题 Been trying for hours and hours to get my multi entity form to work, but it really breaks my head and none of the examples I've found work. I checked the Collection form type documentation and form collections, as well as the Entity form type. I have a User entity, UserRole entity and a Role entity. UserRole contains a userID and a roleID. Just a linking table. The form shows fields to create a User and I want to be able to as well select a new Role for the new user. So I've tried to use the

Symfony 4 multiple entities in single form

好久不见. 提交于 2020-12-08 12:38:41
问题 Been trying for hours and hours to get my multi entity form to work, but it really breaks my head and none of the examples I've found work. I checked the Collection form type documentation and form collections, as well as the Entity form type. I have a User entity, UserRole entity and a Role entity. UserRole contains a userID and a roleID. Just a linking table. The form shows fields to create a User and I want to be able to as well select a new Role for the new user. So I've tried to use the

Symfony functional test fail but the same request works in browser

核能气质少年 提交于 2020-12-08 07:15:07
问题 I followed the Symfony documentation about functional tests in order to write my first one, but I have some issues. The response I get via browser works good: But when I run phpunit -c app/ in the shell I get a failure. 1) AppBundle\Tests\Controller\MeterAPIControllerTest::testGetAllVariables Failed asserting that 500 matches expected 200. This is the code: <?php namespace AppBundle\Tests\Controller; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class MeterAPIControllerTest extends