Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all 3924 articles
Browse latest View live

The lock file is not up to date with the latest changes in composer.json

$
0
0

I'm trying to clone a github repository and issue a composer install on it. But I am getting this:

Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.

Your requirements could not be resolved to an installable set of packages.    Problem 1      - Conclusion: remove symfony/polyfill-intl-icu v1.9.0      - Installation request for symfony/polyfill-intl-icu v1.9.0 -> satisfiable by symfony/polyfill-intl-icu[v1.9.0].      - Conclusion: remove symfony/process v3.4.15      - symfony/polyfill-intl-icu v1.9.0 requires symfony/intl ~2.3|~3.0|~4.0 -> satisfiable by symfony/symfony[v4.0.0].      - don't install symfony/process v3.4.15|remove symfony/symfony v4.0.0      - don't install symfony/symfony v4.0.0|don't install symfony/process v3.4.15      - Installation request for symfony/process v3.4.15 -> satisfiable by symfony/process[v3.4.15].  

When running composer update

Problem 1- Conclusion: don't install symfony/symfony v4.1.7- Conclusion: don't install symfony/symfony v4.1.6- Conclusion: don't install symfony/symfony v4.1.5- Conclusion: don't install symfony/symfony v4.1.4- Conclusion: don't install symfony/symfony v4.1.3- Conclusion: don't install symfony/symfony v4.1.2- Conclusion: don't install symfony/symfony v4.1.1- Conclusion: don't install symfony/symfony v4.1.0- Conclusion: don't install symfony/symfony v4.0.14- Conclusion: don't install symfony/symfony v4.0.13- Conclusion: don't install symfony/symfony v4.0.12- Conclusion: don't install symfony/symfony v4.0.11- Conclusion: don't install symfony/symfony v4.0.10- Conclusion: don't install symfony/symfony v4.0.9- Conclusion: don't install symfony/symfony v4.0.8- Conclusion: don't install symfony/symfony v4.0.7- Conclusion: don't install symfony/symfony v4.0.6- Conclusion: don't install symfony/symfony v4.0.5- Conclusion: don't install symfony/symfony v4.0.4- Conclusion: don't install symfony/symfony v4.0.3- Conclusion: don't install symfony/symfony v4.0.2- Conclusion: don't install symfony/symfony v4.0.1- Conclusion: remove symfony/symfony v4.0.0- don't install symfony/symfony v4.0.0|remove symfony/process v3.4.15- don't install symfony/process v3.3.0|don't install symfony/symfony v4.0.0

composer.json (require section)

"require": {"php": ">=7.1","symfony/symfony": "~4.0","symfony/process": "^3.3","doctrine/orm": "dev-fork as 2.5.6","doctrine/doctrine-bundle": "1.*","symfony/swiftmailer-bundle": "~3.1","symfony/monolog-bundle": "~3.1","sensio/framework-extra-bundle": "^5.1","graylog2/gelf-php": "^1.4","doctrine/doctrine-migrations-bundle": "^1.1","awt/webauth-bundle": "3.0.*","awt/canvas-client-bundle": "6.2.*"}

How to configure SMTP on symfony 4 using swiftmailer?

$
0
0

I'm working on a project which includes emails sending with swiftmailer withing my application based on symfony4, in development period I was using gmail to send email, it was working well, however when I changed the mailer_url to set up smtp parameter, it wouldnt work, I dont know why, and the same credentials are working in webmailer, but not in my application, e-mails are not sent.it doesnt show any error on the log file, but when I use encryption=ssl it gives me this error on log :

php.WARNING: Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed {"exception":"[object] (ErrorException(code: 0): Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:\nerror:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed at /home/admin/web/myhost.com/public_html/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:94)"} []

this is the mailer_url I'm doing at the moment :

MAILER_URL=smtp://localhost:25?auth_mode=login&username=noreply@myhost.com&password=mypassword

I'm stuck at this point, I dont know if I need to set up something on the server hosting my application, or if I need to configure something that I forgot.

Thanks in advance.

Symfony 4 - How to fix "file not found" constraint violation when updating existing entity?

$
0
0

I have a Symfony 4.2 app where the user can create and update rental properties, picture included. I have a problem when updating a rental, the form can't pass validation because the pre-loaded file isn't found ("constraint violation : file not found"). The new file is uploaded via an unmapped property, uploadedPicture, so there's no conflict.

I had this problem a while ago while updating other entities, and setting the properties with a new File object worked like a charm. So I reused the same logic, but I'm still getting an error.

Controller :

$pictureFileName = $rental->getPicture();$rental->setPicture(       new File($this->getParameter('rental_directory').'/'. $pictureFileName)       );$form = $this->createForm(RentalEditType::class, $rental);$form->handleRequest($request);if ($form->isSubmitted()) {      // error happens here I think, but I'll give you my updating logic too       if ($form->isValid()) {            $uploadedFile = $rental->getUploadedPicture();            if($uploadedFile != null) {                $pictureFileName = $this->generateUniqueFileName().'.'.$uploadedFile ->guessExtension();                $uploadedFile ->move(                    $this->getParameter('rental_directory'),                    $pictureFileName                 );             }             $rental->setPicture($pictureFileName );        }        $this->getDoctrine()->getManager()->flush();

Rental.php

/**     * @ORM\Column(type="string", length=255, nullable=true)     * @Assert\File(     *      maxSize = "1M"     * )     *      */    private $picture;//**     * @Assert\File(     *      maxSize = "1M"     * )     */    private $uploadedPicture;

dump($form->getData())

...-picture: File {#215 ▼    path: "assets/uploads/rentals" // right path    filename: "6040e7ca7792be299ce5b72da6339596.jpg" // right filename    basename: "6040e7ca7792be299ce5b72da6339596.jpg"    pathname: "assets/uploads/rentals/6040e7ca7792be299ce5b72da6339596.jpg"    extension: "jpg"    realPath: "/home/ubuntu/workspace/website/public/assets/uploads/rentals/6040e7ca7792be299ce5b72da6339596.jpg"    aTime: 2019-06-22 20:58:36    mTime: 2019-06-22 20:55:57    cTime: 2019-06-22 20:55:57    inode: 1070    size: 724226    perms: 0100644    owner: 1000    group: 1000    type: "file"    writable: true    readable: true    executable: false    file: true    dir: false    link: false  }...

Strange thing is, when I dump form data, the File is found, it gives me a File object and not a string (the path that I registered in the database) which is what I want, but it doesn't seem to work properly since it can't pass validation. The given path seems right too, and the file exists. All the dumps return what should be expected, files, paths... so why am I getting this error and how can I fix it ?

Thanks !

Symfony 4 S3Client::factory issue: 'class Aws\S3\S3Client not found'

$
0
0

I am trying getObject() from aws bucket, but when try s3Client, error: 'class Aws\S3\S3Client not found'

$s3Client = S3Client::factory(['credentials' => ['key'    => $key,'secret' => $secret  ],'region' => $region,'version' => 'latest','scheme' => 'http'             ]);

Symfony 4 Component Process pass arguments for command

$
0
0

Symfony Component Process

/**     * @param array          $command The command to run and its arguments listed as separate entries     * @param string|null    $cwd     The working directory or null to use the working dir of the current PHP process     * @param array|null     $env     The environment variables or null to use the same environment as the current PHP process     * @param mixed|null     $input   The input as stream resource, scalar or \Traversable, or null for no input     * @param int|float|null $timeout The timeout in seconds or null to disable     *     * @throws LogicException When proc_open is not installed     */    public function __construct($command, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60)    { .. }

I have created a command and I use the component Process in my controller.
When I try to run Process I get a ProcessFailException
The command "app:load-file foo bar foobar" failed
Exit Code: 1(General error)
.. ErrorOutput: The filename, directory name, or volume label syntax is incorrect

use Symfony\Component\Process\Process;..public function loadFile(KernelInterface $kernel) {   $argument1 = 'foo';   $argument2 = 'bar';   $argument3 = 'foobar';   $rootDir = $kernel->getProjectDir();   $process = new Process(array(      $rootDir . '/bin/console app:load-file',      $argument1,      $argument2,      $argument3   ));   $process->mustRun();}

What is the correct syntax to run the command from the controller ?
/* *@param array $command The command to run and its arguments listed as separate entries
public function __construct($command, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60){ .. }

Doctrine DQL : Expected known function, got 'acos'

$
0
0

I downloaded "Beberlei" package with composer.

Everything is correctly added in my project :

enter image description here

I changed the file config/"doctrine.yaml" by adding those functions :enter image description here

I'm trying to use them like this :

  public function findCitiesInRange()    {        $lat = 49.3167;        $lng = 2.55;        return $this->createQueryBuilder('v')            ->select('v')            ->addSelect('(6371 * acos(cos(radians(:lat)) * cos(radians(v.latitude)) * cos(radians(v.longitude) - radians(:lng)) + sin(radians(:lat)) * sin(radians(v.latitude)))) AS distance')            ->having('distance <= 50')            ->setParameter('lat', $lat)             ->setParameter('lng', $lng)             ->getQuery()            ->getResult()        ;    }

I get a "Syntax Error" :

enter image description here

Symfony retrieve Unique values from EAV model

$
0
0

I'm trying to make product filters but I can't generate a correct query

А quick look at the basedb visually

here are my entities:

AttributeType:

/** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */private $id;/** * @ORM\Column(type="string", length=100, nullable=true) */private $name;/** * @ORM\OneToMany(targetEntity=AttributeValue::class, mappedBy="attributeType") */private $attributeValue;public function __construct(){    $this->attributeValue = new ArrayCollection();}

AttributeValue:

/** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */private $id;/** * @ORM\ManyToOne(targetEntity=Product::class, inversedBy="attributeValues") */private $product;/** * @ORM\Column(type="string", length=100) */private $value;/** * @ORM\ManyToOne(targetEntity=AttributeType::class, inversedBy="attributeValue") */private $attributeType;

For example AttributeType(Color) has AttributeValue(Red, Blue, Green) & i retrieve hundred of red, blue, green AttributeValue for a single Color option

that query returns options with all value(not unique):

        return $this->createQueryBuilder('at')        ->innerJoin('at.attributeValue', 'attribute_value')        ->addSelect('attribute_value')        ->getQuery()        ->getResult();

I tried to modify the request like this:

        return $this->createQueryBuilder('at')    ->innerJoin('at.attributeValue', 'attribute_value')    ->addSelect('attribute_value.value')->distinct()    ->getQuery()    ->getResult();

(there were other attempts, but they were all not even close)

How do I get unique values for each option?

I will be grateful for any help

And thx for your time.

cron task throws /bin/sh: 1: *: not found

$
0
0

I have two cron tasks running on my Symfony project and the first one is running correctly but in second, log file writes and error:

/bin/sh: 1: *: not found

and I don't know what can be cause of problem..

* * * * *  /usr/local/bin/php /var/www/html/bin/console app:check-status >> /var/www/html/var/log/post.errors.cron.log 2>&1; * * * * *  /usr/local/bin/php /var/www/html/bin/console app:save-status >> /var/www/html/var/log/user.report.cron.log 2>&1

What happened to easyadmin FileUpload type in Symfony4?

$
0
0

In symfony4, in easyadmin, you can use a file_upload field type:

form:     fields:         - {property: 'filepath', label: 'Filename', type: 'file_upload' }

As described here for symfony2

https://symfony.com/doc/2.x/bundles/EasyAdminBundle/book/edit-new-configuration.html#file-upload

But it doesn't seem to be in the current docs anymore; if you google around, you get complicated articles about creating listeners and services, which is probably all very good. But the file_upload still works.

Has it been deprecated ?

Cannot autowire service: Argument references class but no such service exists

$
0
0

I'm upgrading a project from Symfony 3 to Symfony 4 (https://github.com/symfony/symfony/blob/master/UPGRADE-4.0.md) and I have many repository/services like this:

namespace App\Entity;use App\Entity\Activation;use Doctrine\ORM\EntityRepository;use Predis\Client;class ActivationRepository extends EntityRepository{    // ...}

And when I try to run the project in the browser like this:

http://localhost:8000/login

I get this error:

(1/1) RuntimeExceptionCannot autowire service "App\Entity\ActivationRepository": argument "$class" of method "Doctrine\ORM\EntityRepository::__construct()"references class "Doctrine\ORM\Mapping\ClassMetadata"but no such service exists.

Does this mean you have to create a service for "Doctrine\ORM\Mapping\ClassMetadata" in your services.yaml file?

Thanks to autowiring my new services.yaml file is fairly small compared to the old one, which had 2000+ lines.The new services.yaml just has several of these (so far):

App\:    resource: '../src/*'# ControllersApp\Controller\:    resource: '../src/Controller'    autowire: true    public: true    tags: ['controller.service_arguments']# ModelsApp\Model\:    resource: '../src/Model/'    autowire: true    public: true// etc

Question:Do you really need to add service definitions to services.yaml for third party vendor classes? And if so, can I get an example of how to do that please?Any advice from anyone who has already upgraded from Symfony 3 to Symfony 4 would be great.

PHP 7.2.0-2+ubuntu16.04.1+deb.sury.org+2 (cli) (built: Dec 7 2017 20:14:31) ( NTS )Linux Mint 18, Apache2 Ubuntu.

EDIT / FYI:

This is the "Doctrine\ORM\EntityRepository::__construct()" which the ActivationRepository extends:

/**     * Initializes a new <tt>EntityRepository</tt>.     *     * @param EntityManager         $em    The EntityManager to use.     * @param Mapping\ClassMetadata $class The class descriptor.     */    public function __construct(EntityManagerInterface $em, Mapping\ClassMetadata $class)    {        $this->_entityName = $class->name;        $this->_em         = $em;        $this->_class      = $class;    }

which is located here:

/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php

KNP Menu Symfony 4 Custom using twig template

$
0
0

I'm trying to create custom KNP Menu from knplabs/knp-menu-bundle using a template/html twigBut I can't figure out how to do it even following the syfmony.com tutorialAlso I can do it by creating it as a service and using the MenuBuilder.php file.How do I create a knp menu as service using a twig template?

Symfony/Twig: How to force locale in Twig after setLocale is deprecated

$
0
0

I need to render documents in different languages. Therefore I used to use the following code:

use Symfony\Component\Translation\TranslatorInterface;....$this->translator->setLocale($documentData->getLocale());$html = $this->templating->render('admin/request/pdf/document.pdf.twig', ['data' => $data,]);...

And everything worked fine.

But then "Symfony\Component\Translation\TranslatorInterface" got deprecated and one should use "Symfony\Contracts\Translation\TranslatorInterface". In the new class there is no "setLocale()" anymore.

I tried a lot of things but I finally have no idea to work around.

Did anyone mange it?

Thanks a lot!

FOS UserBundle UserManager::__construct() must be an instance of ObjectManager

$
0
0

Fresh installation of symfony 4.4, then symfony flex and some common recipes, then I was trying to setup fos userbundle, I have this issue I cannot get around, any clue to what's going on here, please :)

Argument 3 passed to FOS\UserBundle\Doctrine\UserManager::__construct() must be an instance of Doctrine\Common\Persistence\ObjectManager, instance of Doctrine\ORM\EntityManager given, called in /srv/www/alexseif/var/cache/dev/ContainerYzHcxci/srcApp_KernelDevDebugContainer.php on line 1660

Which is your preferred IDE specifically for symfony 4 programming? [closed]

$
0
0

My question is very simple.

Part of my job is revise symfony 4 code, propose improvements and normalize it, and I was happy using Sublime Text for this, it's just a 10'-15' per day task.

But now, we grow up, and I have to code some specific part of the code by myself, and I do not feel comfortable with netbeans, the IDE used by my partners, so, in your experience, Which is your preferred IDE specifically for symfony 4 programming?

How to redirect to a specific section of a page? [duplicate]

$
0
0

At the bottom of my HomepageI have a contact form. After the user submits the form I want to redirect him to that specific Section.

Which is the bottom of the page. (So he can see the form errors, or he sees "your message was successfully sent" )

Currently, on my controller, I have :

$message = new Messages();$form = $this->createForm(MessagesType::class, $message);$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()) {    $entityManager = $this->getDoctrine()->getManager();    $entityManager->persist($message);    $entityManager->flush();    return $this->redirectToRoute('index_page');}

Instead of redirecting to the page (/), I want to redirect to the #contact section of the page.

  • I tried return $this->redirectToRoute('index_page#contact');
  • Also tried return $this->redirectToRoute('index_page/#contact');

None of them worked. How can I do that?


Doctrine and PostgreSQL - You might need to add explicit type casts

$
0
0

I have wrote a query builder within my Symfony project and I need to return all users with same role.I am using PostgreSQL and as I figured out I need to cast my data as text when using LIKE operator.

I am struggling for days to return results but the error is pretty much the same:

No operator matches the given name and argument type(s). You might need to add explicit type casts.

This is my code:

       $role = 'ROLE_ADMIN';        $query = $this->createQueryBuilder('p')            ->where('p.roles::text LIKE :roles')            ->setParameter('roles', '%'.$role.'%')            ->getQuery();        return $query->getResult();

DB roles filed:

["ROLE_USER","ROLE_ADMIN"]

Non of the related posts helped me.

How to redirect to a specific section of a page? [duplicate]

$
0
0

At the bottom of my HomepageI have a contact form. After the user submits the form I want to redirect him to that specific Section.

Which is the bottom of the page. (So he can see the form errors, or he sees "your message was successfully sent" )

Currently, on my controller, I have :

$message = new Messages();$form = $this->createForm(MessagesType::class, $message);$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()) {    $entityManager = $this->getDoctrine()->getManager();    $entityManager->persist($message);    $entityManager->flush();    return $this->redirectToRoute('index_page');}

Instead of redirecting to the page (/), I want to redirect to the #contact section of the page.

  • I tried return $this->redirectToRoute('index_page#contact');
  • Also tried return $this->redirectToRoute('index_page/#contact');

None of them worked. How can I do that?

Symfony API transforming date

$
0
0

I'm making an API with Symfony 4 and I'm trying to get it to accept a date, but it keeps throwing the Unable to transform data for property path "dateofbirth": Expected a string. error.

Field in entity:

/** * @ORM\Column(type="date", nullable=true) */private $dateofbirth;

Field in Form:

->add('dateofbirth', DateType::class, ['html5' => false,'required' => false,'input' => 'string','input_format' => 'Y-m-d'])

Now if I send it JSON with "dateofbirth": "1990-02-12" for example, it throws that error. I've also tried sending something like "dateofbirth": "1990-02-12T00:00:00+01:00" with the 'input_format' set to Y-m-d\TH:i:sP, but I get the same issue.

I've been messing around with the options array for a while now and I've also tried configurations other than the one above, but that's what I have right now. Instead of listing all the ones I've tried that didn't work, I hope someone can just tell me what does.

how to select an element inside FormType symfony?

$
0
0

this works fine

  $(document).ready(function () {        $('#banner_description').on('keyup', function () {            alert( this.value );        })    });

and when i need to catch the change event when i do upload images its doesn't work i would like to allow to upload just 4 images there is any solution ?

    $('#banner_images').on('upload', function () {        alert( this.value.length );    })

Form Type inspecct

How to redirect to a specific section of a page? [duplicate]

$
0
0

At the bottom of my HomepageI have a contact form. After the user submits the form I want to redirect him to that specific Section.

Which is the bottom of the page. (So he can see the form errors, or he sees "your message was successfully sent" )

Currently, on my controller, I have :

$message = new Messages();$form = $this->createForm(MessagesType::class, $message);$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()) {    $entityManager = $this->getDoctrine()->getManager();    $entityManager->persist($message);    $entityManager->flush();    return $this->redirectToRoute('index_page');}

Instead of redirecting to the page (/), I want to redirect to the #contact section of the page.

  • I tried return $this->redirectToRoute('index_page#contact');
  • Also tried return $this->redirectToRoute('index_page/#contact');

None of them worked. How can I do that?

Viewing all 3924 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>