i have a question, when i load for the first time my symfony 4 project, itis very slow to load a app.js.
i already execute cache:clear but nothing. Somoeone can help me please
i have a question, when i load for the first time my symfony 4 project, itis very slow to load a app.js.
i already execute cache:clear but nothing. Somoeone can help me please
I am developing a "Symfony" project with a group of people but I cannot install the ext-HTTP extension needed to run the code properly, using Pecl install doesn't work either. I am using a mac OS Catalina.
I tried installing the extension with pecl but it didn't work, I also cannot just enable it from the 'PHP.ini' file. all the answers I find are related to either Ubuntu or windows, so I cannot solve it with those solutions. let me know if you guys know a fix
I've got a set of entities for which I have a field owned
. I need to set owned
manually as it's dependent on both a ManyToMany and an inherited system (if a user owns a Course
they also own all Subject
within, etc).
This class is retrieved from the database using Doctrine ORM annotations. Originally I wanted to set it inside the App\Entity
declaration, but since this isn't good practice, I've been looking at maybe using an event listener or factory. I'm stuck with how to do this.
For example, the following is what I'm wanting to set based on the current logged in user.
class Course {
private $owned = false;
public function getOwned(): ?bool
{
return $this->owned;
}
public function setOwned( bool $state )
{
$this->owned = $state;
return $this;
}
I am starting to play with symfony4. I've just created new application and create new LuckyController. It works with routes.yaml configured in this manner:
lucky:
path: /lucky/number
controller: App\Controller\LuckyController::number
With the following controller:
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
class LuckyController
{
public function number()
{
return new Response('<html><head></head><body>' . rand(111, 999) . '</body></html>');
}
}
But I want to use annotations. So I decided to comment routes.yaml. Following documentation that explain how to create a route in symfony I've made this:
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class LuckyController extends Controller
{
/**
* @Route("/lucky/number")
*/
public function number()
{
return new Response('<html><head></head><body>' . rand(111, 999) . '</body></html>');
}
}
I have feature that is based on current date, and the question is if it is good solution to write if condition in scenario. Simple example: if tested date is equal to current then other field is equal to 0 else equal 10. Meybe there are libraries to mock current date time in symfony 4.
I have a FormType with a FileType field used to upload images I'd like in first case to define this field as required and in not in the second
->add('file', FileType::class, [
'label' => 'Photo en rapport avec la figure',
'attr' => ['placeholder' => 'Télécharger une photo'],
'required' => false, // contrainte au niveau front
'empty_data' => null
in my first form template this FileType belongs to a CollectionType so I wrote
{{ form_label(form.photos.file) }}
{{ form_widget(form.photos.file.{'attr':{'required':'required'}}) }}
{{ form_errors(form.photos.file) }}
but i didn't works and gives an error "Expected name or number." which puzzled me
I am trying to solve a problem related with token request. It is my newArticle function (to add new article) in the controller:
public function newArticle(Request $request, EntityManagerInterface $entityManager): View
{
$data = json_decode($request->getContent(), true);
$title = $data['title'];
$content = $data['content'];
//$published_at = $data['published_at'];
$authorizationHeader = $request->headers->get('Authorization');
list(,$token) = explode('', $authorizationHeader);
$jwtToken = $this->JWTEncoder->decode($token);
$user_id = $data[$jwtToken];
$userId = $this->userRepository->findOneBy(['id' => $user_id['id']]);
$article = new Article();
$article->setTitle($title);
$article->setContent($content);
$article->setPublishedAt(new \DateTime());
$article->setUser($userId);
// Todo: 400 response - Invalid input
// Todo: 404 response - Response not found
// Incase our Post was a success we need to return a 201 HTTP CREATED response with the created object
if(in_array('ROLE_USER', $article->getUser()->getRoles(), true)) {
$entityManager->persist($article);
$entityManager->flush();
return View::create("You added an article successfully!", Response::HTTP_OK);
} else {
return View::create(["You are not a user! So please register to add an article!"], Response::HTTP_BAD_REQUEST);
}
}
It is working before adding token header authorization and now I got this error:
"error": {
"code": 500,
"message": "Internal Server Error",
"message": "Notice: Undefined offset: 1",
Can someone give me any suggestions?
it is going to be lengthy post, I encountering weird behavior where I see in profiler that one entity managers is said to map entity that it does not map. It looks like this:Here is doctrine.yaml:
doctrine: dbal: default_connection: default connections: default: driver: "pdo_mysql" host: "127.0.0.1" port: "3306" dbname: "example" user: "root" password: "" charset: utf8mb4 server_version: "mariadb-10.4.10" logs: driver: "pdo_mysql" host: "127.0.0.1" port: "3306" dbname: "example_logs" user: "root" password: "" charset: utf8mb4 server_version: "mariadb-10.4.10" orm: auto_generate_proxy_classes: true default_entity_manager: default entity_managers: default: query_cache_driver: type: pool pool: apcu.default.cache.pool metadata_cache_driver: type: pool pool: apcu.default.cache.pool result_cache_driver: type: pool pool: apcu.default.cache.pool connection: default naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware mappings: App: is_bundle: false type: annotation dir: '%kernel.project_dir%/src/Entity/Main' prefix: 'App\Entity\Main' alias: App logs: query_cache_driver: type: pool pool: apcu.default.cache.pool metadata_cache_driver: type: pool pool: apcu.default.cache.pool result_cache_driver: type: pool pool: apcu.default.cache.pool connection: logs naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware mappings: LogBundle: is_bundle: false type: annotation dir: '%kernel.project_dir%/src/Entity/Logs' prefix: 'App\Entity\Logs' alias: App
And here is framework.yaml with cache pool configuration:
framework: secret: '%env(APP_SECRET)%' session: handler_id: null cookie_secure: auto cookie_samesite: lax php_errors: log: true cache: pools: apcu.default.cache.pool: adapter: cache.adapter.apcu apcu.logs.cache.pool: adapter: cache.adapter.apcu
If I remove metadata_cache_driver
configuration from logs entity_manager
configuration, or change it to use different cache pool (apcu.logs.cache.pool) than default entity manager then profiler reports correct mappings (Example entity in default em and logs em is empty).
The issue occurs only when entity is feed trough form and $form->handleRequest()
handles it, creating or modifying entity without forms does not cause such issue. Here is my controller:
<?phpnamespace App\Controller;use App\Entity\Main\Example;use App\Form\Type\ExampleType;use Doctrine\ORM\EntityManagerInterface;use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Annotation\Route;class ExampleController extends AbstractController { /** * @Route("/example1") * @Template */ public function example1(EntityManagerInterface $em){ $example = new Example(); $example->setValue('example value'); try { $em->persist($example); $em->flush(); } catch(\Exception $e){ return new Response('An error has occurred. '.$e->getMessage()); } return []; } /** * @Route("/example2") * @Template */ public function example2(EntityManagerInterface $em){ $example = $em->getRepository(Example::class)->find(1); if(!$example){ return new Response('No example found.'); } $example->setValue(mt_rand(0, mt_getrandmax())); try { $em->flush(); } catch(\Exception $e){ return new Response('An error has occurred. '.$e->getMessage()); } return []; } /** * @Route("/example3") * @Template */ public function example3(Request $request, EntityManagerInterface $em){ $example = $em->getRepository(Example::class)->find(1); if(!$example){ return new Response('No example found.'); } $form = $this->createForm(ExampleType::class, $example); $form->handleRequest($request); if($form->isSubmitted() && $form->isValid()){ $em->flush(); } return ['form' => $form->createView()]; }}
example1 and example2 routes DOES NOT cause issue, only example3 does and only when the form is submitted, so only when I enter example3 url, then click submit form only then when enter profiler for this request I can see the issue.
My minimal reproduction example was to create new symfony LTS project symfony new example-site --version=lts --full
Then these are files that I have changed since:
Databases are created by symfony console doctrine:database:create --connection=default
and symfony console doctrine:database:create --connection=logs
then tables are created by symfony console doctrine:migrations:diff --em=default
and symfony console doctrine:migrations:migrate --em=default
Here is code for other files I haven't yet included in post:
<?php//src/Entity/Main/Example.phpnamespace App\Entity\Main;use Doctrine\ORM\Mapping as ORM;/** * @ORM\Entity */class Example { /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string") */ private $value; public function getId(){ return $this->id; } public function getValue(){ return $this->value; } public function setValue(string $value){ $this->value = $value; }}
<?php//src/Form/Type/ExampleType.phpnamespace App\Form\Type;use App\Entity\Main\Example;use Symfony\Component\Form\AbstractType;use Symfony\Component\Form\Extension\Core\Type\SubmitType;use Symfony\Component\Form\Extension\Core\Type\TextType;use Symfony\Component\Form\FormBuilderInterface;use Symfony\Component\OptionsResolver\OptionsResolver;class ExampleType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options){ $builder->add('value', TextType::class); $builder->add('submit', SubmitType::class); } public function configureOptions(OptionsResolver $resolver){ $resolver->setDefaults(['data_class' => Example::class, ]); }}
<!-- template/s/example/example1.html.twig --><!doctype html><html lang="en"><head><meta charset="utf-8"><title>Example</title></head><body> Example1</body></html>
<!-- template/s/example/example2.html.twig --><!doctype html><html lang="en"><head><meta charset="utf-8"><title>Example</title></head><body> Example2</body></html>
<!-- template/s/example/example3.html.twig --><!doctype html><html lang="en"><head><meta charset="utf-8"><title>Example</title></head><body>{{ form(form) }}</body></html>
Last thing I want to add is that in other project this issue is more visible, because when entity has reference to other entity an error is reported (on non-owning side in One-to-Many self-referencing association):In this case Item entity is the one feed trough form.For those who are curious here is Item.php:But I don't know how would it matter as it is not managed by logs entity manager and should not appear under. default entity manager who is managing the entity is not reporting any issues with it.
<?phpnamespace App\Entity;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\HttpFoundation\File\UploadedFile;use Symfony\Component\Validator\Constraints as Assert;/** * @ORM\Entity(repositoryClass="App\Repository\ItemRepository") * @ORM\Table(indexes={ * @ORM\Index(name="item_image", columns={"image"}) * }) */class Item { /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=32) * @Assert\NotBlank() * @Assert\Length(min=3, max=32) */ private $name; /** * @ORM\Column(type="string") */ private $description = ''; /** * @ORM\Column(type="string", length=25, nullable=true) */ private $image; /** * @ORM\OneToMany(targetEntity="App\Entity\Item", mappedBy="container") */ private $items; /** * @ORM\ManyToOne(targetEntity="App\Entity\Item", inversedBy="items") * @ORM\JoinColumn(name="container", referencedColumnName="id") * @var $container Item */ private $container; /** * @ORM\OneToMany(targetEntity="App\Entity\TagItem", mappedBy="item") * @var $tags TagItem[] */ private $tags; /** * @Assert\Image(mimeTypes="image/jpeg") * @var $imageFile null|UploadedFile */ private $imageFile; public function __construct() { $this->items = new \Doctrine\Common\Collections\ArrayCollection(); $this->tags = new \Doctrine\Common\Collections\ArrayCollection(); } public function getId(){ return $this->id; } public function getName(){ return $this->name; } public function setName(string $name){ $this->name = $name; } public function getDescription(){ return $this->description; } public function setDescription($description){ $this->description = $description; } public function hasImage(){ return isset($this->image); } public function getImage(){ return $this->image; } public function setImage($image){ $this->image = $image; } public function hasImageFile(){ return isset($this->imageFile); } public function getImageFile(){ return $this->imageFile; } public function setImageFile($imageFile){ $this->imageFile = $imageFile; } public function getItems(){ return $this->items; } public function hasContainer(){ return isset($this->container); } public function getContainer(){ return $this->container; } public function setContainer(?Item $container){ return $this->container = $container; } public function getTags(){ return $this->tags; } public function setTags($tags){ $this->tags = $tags; }}
PHP version is 7.3.12 and hosted with symfony serve
I set up a search form with a handmade Entity but the form does not transmit the info to the entity ... you have an idea to solve this problem?
Also it's symfony 4.4 and I've already checked the findWeeklyPlanningRs query in the repository and it works fine.
this is the entity:
<?phpnamespace App\Entity ;class FilterWeek{ private $nbWeek ; public function getNbWeek(): ?int { return $this-> nbWeek; } public function setNbWeek(int $nbWeek): self { $this->$nbWeek = $nbWeek; return $this; }}
the Controller
/** * @Route("/{id}/week" , name="week") */ public function weeklyPlanning(Request $request , $id ) : Response { $em = $this->getDoctrine()->getManager(); $week = new FilterWeek(); $form = $this -> createForm(FilterWeekType::class , $week ) ; $form->handleRequest($request); $planning = $em -> getRepository(Chargement::class) -> findWeeklyPlanningRs($id , $week-> getNbWeek() ) ; $responsableSecteur = $em ->getRepository(ResponsableSecteur::class)->find($id) ; return $this -> render('Planing/ResponsableSecteurWeek.html.twig' , ['responsable_secteur' => $responsableSecteur,'chargements' => $planning ,'form' => $form -> createView() ] ); }
the form :
<?phpnamespace App\Form;use App\Entity\FilterWeek;use Symfony\Component\Form\AbstractType;use Symfony\Component\Form\FormBuilderInterface;use Symfony\Component\OptionsResolver\OptionsResolver;use Symfony\Component\Form\Extension\Core\Type\IntegerType;class FilterWeekType extends AbstractType{ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('nbWeek' , IntegerType::class , ['label' => 'numéro de la semaine' ,'required' => false ]) ; } public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(['data_class' => FilterWeek::class,'method' => 'get','csrf_protection' => false, ]); } public function getBlockPrefix(){ return ''; }}
the view :
{% extends 'base.html.twig' %}{% block body %}<div class="container"><h3>Planning des chargements par Semaine</h3><br><br><div class="form-row"><div class="col-4"> {{ form_start(form) }} {{ form_row(form.nbWeek) }}<button class="btn color-br" style="top : 5em;">Rechercher</button> {{ form_end(form) }}</div>
I have trouble upgrading Symfony 3.4 version to 4 version.
I followed some instructions that I found online, and I think the problem is with some of the packages from my .json file.
Could someone tell what should be done with .json configuration? I have my 3.4 project running fine with this json file.
"require": {"php": "^7.2","ext-curl": "*","ext-json": "*","abraham/twitteroauth": "^0.7.4","chillerlan/php-qrcode": "^2.0","cron/cron-bundle": "^1.2","doctrine/doctrine-bundle": "^1.6","doctrine/doctrine-migrations-bundle": "^1.0","doctrine/orm": "^2.5","fresh/vich-uploader-serialization-bundle": "~2.0","friendsofsymfony/user-bundle": "~2.0","icanboogie/inflector": "^1.4","incenteev/composer-parameter-handler": "^2.0","inscouts/rms-push-notifications-bundle": "^0.2.0","intervention/image": "^2.4","javiereguiluz/easyadmin-bundle": "^1.17","jeroendesloovere/vcard": "^1.7","knplabs/knp-paginator-bundle": "^2.7","lexik/jwt-authentication-bundle": "^2.4","nyholm/psr7": "^1.2","phpoffice/phpexcel": "^1.8","phpoffice/phpspreadsheet": "^1.6","psr/http-client": "^1.0","sensio/framework-extra-bundle": "^5.0.0","stof/doctrine-extensions-bundle": "^1.3","suncat/mobile-detect-bundle": "^1.1","symfony/filesystem": "^3.4","symfony/monolog-bundle": "^3.1.0","symfony/polyfill-apcu": "^1.0","symfony/serializer": "^3.0","symfony/swiftmailer-bundle": "^3.1","symfony/symfony": "^4","symfony/var-dumper": "^3.0","twig/twig": "^1.0||^2.0","vich/uploader-bundle": "^1.8"},"require-dev": {"symfony/phpunit-bridge": "^4"},"scripts": {"symfony-scripts": ["Incenteev\\ParameterHandler\\ScriptHandler::buildParameters","bin/console cache:clear --env prod","bin/console cache:clear","bin/console assets:install --symlink --relative web"...
I'm using Symfony 4 and the EasyAdmin Bundle to create my forms.
I want to build a form to create a new Product where you have to choose between 3 models with a ManyToOne relation.In these models there are :
It's just a small example to make it simple for me to explain.So I when I'm creating a new Product and when I choose between one of the 3 models availables, I want to be able to fill their variables too.
For example if I choose Model 1 in the Product form I can fill the text and the data. Then when I save it, it create the Product and the Model 1 associated to the Product.
So my question is : How can I achieve that ? I tried to create a custom html.twig template to create my form, but then I don't know how to access the variables of a model. Is it even possible to do that using EasyAdmin bundle ?
Thanks in advance for your help !
I'm struggling to configure monolog properly.
I keep receiving these messages in my /var/logs/prod.log
2020-04-02 18:26:01] php.INFO: User Deprecated: Using the "templating" service is deprecated since version 4.3 and will be removed in 5.0; use Twi....
[2020-04-02 18:26:01] php.INFO: User Deprecated: The "twig.exception_listener" service is deprecated since Symfony 4.4. {"exception":"[object] (Err...
[2020-04-02 18:26:01] php.INFO: User Deprecated: The "Symfony\Component\HttpKernel\EventListener\ExceptionListener" class is deprecated since Symfo....
Despite setting up the minimum level to error, it only seems to work for app.* type of logs and not php.*
Here is my prod/monolog.yaml
monolog: handlers: main: type: fingers_crossed action_level: warning handler: nested excluded_http_codes: [404, 405] nested: type: stream path: "%kernel.logs_dir%/%kernel.environment%.log" level: warning console: type: console process_psr_3_messages: false channels: ["!event", "!doctrine"] deprecation: type: stream path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log" deprecation_filter: type: filter handler: deprecation max_level: info channels: ["php"]
And in my framework.yaml I also have this bit of code:
framework: php_errors: log: true
Thank you
I'm working on a personnel project (a e-commerce website) and I'm using ReactJS & Symfony. My issue is the following: I created a querybuilder in my file: ChaussureRepository.php to search every element in my table Chaussure where the name contains the word that I'm typing.
ChaussureRepository.php
/** * @return Chaussure[] */public function findByNom($nom){ $query = $this->createQueryBuilder('a') ->where('a.nom LIKE :name') ->setParameter('name', '%'.$nom.'%') ->getQuery(); return $query->getResult();}
ChaussureController.php
* @Route("/recherche/{nom}", name="recherche_chaussure", methods={"get"}) */ public function index($nom) { $chaussures = $this->getDoctrine()->getRepository(Chaussure::class)->findByNom($nom);
My Controller returns me an empty array. When I type a word that is in the name that I'm searching it doesn't work but when I type the full name it works. Someone can help me with my createQueryBuilder to make work LIKE %:name%.
im using easy admin of symfony 4.4.7 the think is if i try to upload a picture (vichupload) im getting an error here
C:\wamp64\www\reddy\vendor\easycorp\easyadminbundle\src\Resources\views\default\field_text.html.twig (line 4)
{% if view == 'show' %} {{ value|nl2br }}{% else %} {{ value|striptags|easyadmin_truncate }}{% endif %}
this is my about entity that im trying to handle via easy admin
class: App\Entity\AboutUs form: fields: - { property: 'imageFile', type: 'vich_image' } - { property: 'title'} - { property: 'content', type: 'text_editor'} list: actions: - {name: 'edit', icon: 'pencil', label: false, css_class: 'btn btn-secondary' } - {name: 'delete', icon: 'trash', label: false, css_class: 'btn btn-danger' } - {name: 'show'} fields: - { property: 'title'} - { property: 'content'} - { property: 'update_at'} - { property: 'image', type: 'image', base_path: '%app.path.product_images%' } show: fields: - { property: 'title'} - { property: 'content'} - { property: 'update_at'} - { property: 'image', type: 'image', base_path: '%app.path.product_images%' }
this is my about entity
<?phpnamespace App\Entity;use DateTime;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\HttpFoundation\File\File;use Vich\UploaderBundle\Mapping\Annotation as Vich;/** * @ORM\Entity(repositoryClass="App\Repository\EboutUsRepository") * @Vich\Uploadable() */class AboutUs{ /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=255) */ private $title; /** * @ORM\Column( type="string", length=255, ) * @var string */ private $image; /** * @ORM\Column(type="string", length=255) */ private $content; /** * @Vich\UploadableField(mapping="product_images", fileNameProperty="image") * @var File */ private $imageFile; /** * @ORM\Column(type="datetime") * @var \DateTime */ private $updateAt; public function __construct() { $this->updateAt = new \DateTime(); } public function getId(): ?int { return $this->id; } public function getTitle(): ?string { return $this->title; } public function setTitle(string $title): self { $this->title = $title; return $this; } public function getImage(): ?string { return $this->image; } public function setImage(?string $image): self { $this->image = $image; return $this; } public function getContent(): ?string { return $this->content; } public function setContent(string $content): self { $this->content = $content; return $this; } public function setImageFile(File $image = null): self { $this->imageFile = $image; if ($image) { $this->updateAt = new DateTime(); } return $this; } public function getImageFile() { return $this->imageFile; } public function getUpdateAt(): ?\DateTimeInterface { return $this->updateAt; } public function setUpdateAt(\DateTimeInterface $updateAt): self { $this->updateAt = $updateAt; return $this; }}
I am working on a project in Symfony 4.2 with Webpack. I'm versioning my code with BitBucket and I'm using heroku for my deployment. The app work very well on dev environnement on my local machine. But I have an error in production mode on Heroku. The server can not find the file manifest.json, and my asset files generate 404 errors.
Here is the contents of my assets.yaml config file:
framework: assets: json_manifest_path: '%kernel.project_dir%/public/build/manifest.json'
Below are the errors I have:
2019-01-23T14:17:36.377047+00:00 app[web.1]: [2019-01-23 14:17:36] request.INFO: Matched route "app_login". {"route":"app_login","route_parameters":{"_route":"app_login","_controller":"App\\Controller\\SecurityController::login"},"request_uri":"http://**********.herokuapp.com/","method":"GET"} []2019-01-23T14:17:36.377226+00:00 app[web.1]: [2019-01-23 14:17:36] security.DEBUG: Checking for guard authentication credentials. {"firewall_key":"main","authenticators":1} []2019-01-23T14:17:36.377448+00:00 app[web.1]: [2019-01-23 14:17:36] security.DEBUG: Checking support on guard authenticator. {"firewall_key":"main","authenticator":"App\\Security\\LoginFormAuthenticator"} []2019-01-23T14:17:36.377787+00:00 app[web.1]: [2019-01-23 14:17:36] security.DEBUG: Guard authenticator does not support the request. {"firewall_key":"main","authenticator":"App\\Security\\LoginFormAuthenticator"} []2019-01-23T14:17:36.379214+00:00 app[web.1]: [2019-01-23 14:17:36] security.INFO: Populated the TokenStorage with an anonymous Token. [] []**2019-01-23T14:17:36.379828+00:00 app[web.1]: [2019-01-23 14:17:36] request.CRITICAL: Uncaught PHP Exception Twig_Error_Runtime: "An exception has been thrown during the rendering of a template ("Asset manifest file "/app/public/build/manifest.json" does not exist.")." at /tmp/build_6b468a926db1e3ce965958cbead3b64f/templates/base.html.twig line 8 {"exception":"[object] (Twig_Error_Runtime(code: 0): An exception has been thrown during the rendering of a template (\"Asset manifest file \"/app/public/build/manifest.json\" does not exist.\"). at /tmp/build_6b468a926db1e3ce965958cbead3b64f/templates/base.html.twig:8, RuntimeException(code: 0): Asset manifest file \"/app/public/build/manifest.json\" does not exist. at /app/vendor/symfony/asset/VersionStrategy/JsonManifestVersionStrategy.php:57)"} []2019-01-23T14:17:36.380146+00:00 app[web.1]: 10.92.136.3 - - [23/Jan/2019:14:17:36 +0000] "GET / HTTP/1.1" 500 918 "-""Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36**
I also tried to disable access to the manifest.json file in the assets.yaml config file. And I get 404 errors on my asset files:
2019-01-23T15:45:20.646929+00:00 app[web.1]: 10.10.240.248 - - [23/Jan/2019:15:45:20 +0000] "GET / HTTP/1.1" 200 3878 "-""Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.362019-01-23T15:45:20.821244+00:00 app[web.1]: 10.10.240.248 - - [23/Jan/2019:15:45:20 +0000] "GET /build/app.css HTTP/1.1" 404 211 "https://***********.herokuapp.com/""Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36 2019-01-23T15:45:20.830189+00:00 app[web.1]: 10.13.65.189 - - [23/Jan/2019:15:45:20 +0000] "GET /build/libs/jquery/tether/dist/js/tether.min.js HTTP/1.1" 404 244 "https:// caisse-fitfit.herokuapp.com/""Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36 2019-01-23T15:45:20.962711+00:00 app[web.1]: 10.10.240.248 - - [23/Jan/2019:15:45:20 +0000] "GET /build/libs/jquery/underscore/underscore-min.js HTTP/1.1" 404 244 "https:/ /*************.herokuapp.com/""Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36 2019-01-23T15:45:20.976373+00:00 app[web.1]: 10.13.65.189 - - [23/Jan/2019:15:45:20 +0000] "GET /build/libs/jquery/jQuery-Storage-API/jquery.storageapi.min.js HTTP/1.1" 40 4 259 "https://*********.herokuapp.com/""Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36 2019-01-23T15:45:21.001653+00:00 app[web.1]: 10.37.18.194 - - [23/Jan/2019:15:45:21 +0000] "GET /build/libs/jquery/PACE/pace.min.js HTTP/1.1" 404 232 "https://caisse-fitfi t.herokuapp.com/""Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36 2019-01-23T15:45:21.111050+00:00 app[web.1]: 10.10.240.248 - - [23/Jan/2019:15:45:21 +0000] "GET /build/scripts/config.lazyload.js HTTP/1.1" 404 230 "https://************ .herokuapp.com/""Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36 2019-01-23T15:45:21.121765+00:00 app[web.1]: 10.13.65.189 - - [23/Jan/2019:15:45:21 +0000] "GET /build/scripts/palette.js HTTP/1.1" 404 222 "https://***********.herokuap p.com/""Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36 2019-01-23T15:45:21.153872+00:00 app[web.1]: 10.37.18.194 - - [23/Jan/2019:15:45:21 +0000] "GET /build/scripts/ui-load.js HTTP/1.1" 404 222 "https://caisse-fitfit.herokuap p.com/""Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36 2019-01-23T15:45:21.160011+00:00 app[web.1]: 10.10.240.248 - -
I tested several solutions found on the net, but none works. :(
I use symfony 4.3 and easycorp/easyadmin-bundle 2.3
I have an Product.yaml file for my Easy Admin platform :
easy_admin: entities: Product: class: App\Entity\Product form: fields: - name - {property: 'doc', type: 'vich_file'} - { property: 'model1', label: 'Model 1', type: 'collection', type_options: {entry_type: 'App\Entity\Model1', by_reference: false} }
/** * @ORM\Entity(repositoryClass="App\Repository\ProductRepository") * @Vich\Uploadable() */class Product{ /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=255) */ private $name; /** * @ORM\Column(type="string", length=255) */ private $doc; /** * @Assert\File( * maxSize = "5M", * mimeTypes = {"application/pdf", "application/x-pdf"} * ) * @Vich\UploadableField(mapping="product_doc", fileNameProperty="doc") */ private $doc_file; /** * @ORM\Column(type="datetime", nullable=true) */ private $updated_at; /** * @ORM\ManyToOne(targetEntity="Model1", inversedBy="products") */ private $model1;
Also a Model1.yaml file :
easy_admin: entities: Model1: class: App\Entity\Model1 form: fields: - intro - details - applications - {property: 'info', type: 'text_editor'}
class Model1{ /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="text") */ private $intro; /** * @ORM\Column(type="text") */ private $details; /** * @ORM\Column(type="text") */ private $applications; /** * @ORM\Column(type="text") */ private $info; /** * @ORM\OneToMany(targetEntity="Product", mappedBy="model1") */ private $products;
And when I try to create a new Product in easy Admin I get an error : Could not load type "App\Entity\Model1": class does not implement "Symfony\Component\Form\FormTypeInterface".
So I decided to create a Model1Type.php :
class Model1Type extends AbstractType{ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('intro', TextareaType::class) ->add('details', TextareaType::class) ->add('applications', TextareaType::class) ->add('info', TextareaType::class) ; } public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(['data_class' => Model1::class, ]); }}
But when then my Model1.yaml seems useless. If I add a new fields in Model1.yaml it don't appear...How can I make this work withot using Model1Type.php and only the Model1.yaml to use the type 'text_editor' present in the easy admin bundle ?
Thank you in advance for your help
My application developed with Symfony 4 in the backend and React js in the frontend, then I want to deploy it on Heroku. I have already connected heroku with my github repository. Finally after I configured everything, I launched the command git push heroku master
, then I found the following error shown below:
git push heroku masterEnumerating objects: 255, done.Counting objects: 100% (255/255), done.Delta compression using up to 4 threadsCompressing objects: 100% (250/250), done.Writing objects: 100% (255/255), 159.41 KiB | 2.61 MiB/s, done.Total 255 (delta 144), reused 0 (delta 0)remote: Compressing source files... done.remote: Building source:remote:remote: -----> PHP app detectedremote: -----> Bootstrapping...remote: -----> Installing platform packages...remote: - php (7.4.4)remote: - ext-gd (bundled with php)remote: - ext-mbstring (bundled with php)remote: - apache (2.4.41)remote: - nginx (1.16.1)remote: -----> Installing dependencies...remote: Composer version 1.10.1 2020-03-13 20:34:27remote: Loading composer repositories with package informationremote: Installing dependencies from lock fileremote: Package operations: 91 installs, 0 updates, 0 removalsremote: - Installing ocramius/package-versions (1.4.2): Downloading (100%)remote: - Installing symfony/flex (v1.6.0): Downloading (100%)remote:remote: Prefetching 89 packagesremote: - Downloading (100%)remote:remote: - Installing doctrine/lexer (1.2.0): Loading from cacheremote: - Installing doctrine/annotations (v1.8.0): Loading from cacheremote: - Installing doctrine/reflection (v1.0.0): Loading from cacheremote: - Installing doctrine/event-manager (1.1.0): Loading from cacheremote: - Installing doctrine/collections (1.6.4): Loading from cacheremote: - Installing doctrine/cache (1.10.0): Loading from cacheremote: - Installing doctrine/persistence (1.3.3): Loading from cacheremote: - Installing doctrine/inflector (1.3.1): Loading from cacheremote: - Installing doctrine/common (v2.11.0): Loading from cacheremote: - Installing doctrine/instantiator (1.3.0): Loading from cacheremote: - Installing psr/container (1.0.0): Loading from cacheremote: - Installing symfony/service-contracts (v1.1.8): Loading from cacheremote: - Installing symfony/stopwatch (v4.3.9): Loading from cacheremote: - Installing symfony/polyfill-php73 (v1.13.1): Loading from cacheremote: - Installing symfony/polyfill-mbstring (v1.13.1): Loading from cacheremote: - Installing symfony/console (v4.3.9): Loading from cacheremote: - Installing zendframework/zend-eventmanager (3.2.1): Loading from cacheremote: - Installing zendframework/zend-code (3.4.1): Loading from cacheremote: - Installing ocramius/proxy-manager (2.2.3): Loading from cacheremote: - Installing doctrine/dbal (v2.10.0): Loading from cacheremote: - Installing doctrine/migrations (2.2.0): Loading from cacheremote: - Installing willdurand/negotiation (v2.3.1): Loading from cacheremote: - Installing willdurand/jsonp-callback-validator (v1.1.0): Loading from cacheremote: - Installing symfony/event-dispatcher-contracts (v1.1.7): Loading from cacheremote: - Installing symfony/security-core (v4.3.9): Loading from cacheremote: - Installing symfony/routing (v4.3.9): Loading from cacheremote: - Installing symfony/polyfill-php72 (v1.13.1): Loading from cacheremote: - Installing symfony/polyfill-intl-idn (v1.13.1): Loading from cacheremote: - Installing symfony/mime (v4.3.9): Loading from cacheremote: - Installing symfony/http-foundation (v4.3.9): Loading from cacheremote: - Installing symfony/event-dispatcher (v4.3.9): Loading from cacheremote: - Installing psr/log (1.1.2): Loading from cacheremote: - Installing symfony/debug (v4.3.9): Loading from cacheremote: - Installing symfony/http-kernel (v4.3.9): Loading from cacheremote: - Installing symfony/finder (v4.3.9): Loading from cacheremote: - Installing symfony/filesystem (v4.3.9): Loading from cacheremote: - Installing symfony/dependency-injection (v4.3.9): Loading from cacheremote: - Installing symfony/config (v4.3.9): Loading from cacheremote: - Installing symfony/var-exporter (v4.3.9): Loading from cacheremote: - Installing psr/cache (1.0.1): Loading from cacheremote: - Installing symfony/cache-contracts (v1.1.7): Loading from cacheremote: - Installing symfony/cache (v4.3.9): Loading from cacheremote: - Installing symfony/framework-bundle (v4.3.9): Loading from cacheremote: - Installing friendsofsymfony/rest-bundle (2.6.0): Loading from cacheremote: - Installing jdorn/sql-formatter (v1.2.17): Loading from cacheremote: - Installing symfony/inflector (v4.3.9): Loading from cacheremote: - Installing symfony/property-access (v4.3.9): Loading from cacheremote: - Installing symfony/security-http (v4.3.9): Loading from cacheremote: - Installing symfony/security-guard (v4.3.9): Loading from cacheremote: - Installing symfony/security-csrf (v4.3.9): Loading from cacheremote: - Installing symfony/security-bundle (v4.3.9): Loading from cacheremote: - Installing namshi/jose (7.2.3): Loading from cacheremote: - Installing lcobucci/jwt (3.3.1): Loading from cacheremote: - Installing lexik/jwt-authentication-bundle (v2.6.5): Loading from cacheremote: - Installing nelmio/cors-bundle (2.0.1): Loading from cacheremote: - Installing phpdocumentor/reflection-common (2.0.0): Loading from cacheremote: - Installing phpdocumentor/type-resolver (1.0.1): Loading from cacheremote: - Installing psr/simple-cache (1.0.1): Loading from cacheremote: - Installing markbaker/matrix (1.2.0): Loading from cacheremote: - Installing markbaker/complex (1.4.7): Loading from cacheremote: - Installing phpoffice/phpspreadsheet (1.10.1): Loading from cacheremote: - Installing sensio/framework-extra-bundle (v5.5.2): Loading from cacheremote: - Installing symfony/apache-pack (v1.0.1): Loading from cacheremote: - Installing symfony/doctrine-bridge (v4.3.9): Loading from cacheremote: - Installing symfony/dotenv (v4.3.9): Loading from cacheremote: - Installing symfony/options-resolver (v4.3.9): Loading from cacheremote: - Installing symfony/intl (v4.3.9): Loading from cacheremote: - Installing symfony/polyfill-intl-icu (v1.13.1): Loading from cacheremote: - Installing symfony/form (v4.3.9): Loading from cacheremote: - Installing egulias/email-validator (2.1.15): Loading from cacheremote: - Installing symfony/mailer (v4.3.10): Loading from cacheremote: - Installing symfony/google-mailer (v4.3.11): Loading from cacheremote: - Installing nikic/php-parser (v4.3.0): Loading from cacheremote: - Installing symfony/maker-bundle (v1.14.3): Loading from cacheremote: - Installing monolog/monolog (1.25.2): Loading from cacheremote: - Installing symfony/monolog-bridge (v4.3.9): Loading from cacheremote: - Installing symfony/monolog-bundle (v3.5.0): Loading from cacheremote: - Installing doctrine/orm (v2.7.0): Loading from cacheremote: - Installing doctrine/doctrine-bundle (2.0.2): Loading from cacheremote: - Installing doctrine/doctrine-migrations-bundle (2.1.2): Loading from cacheremote: - Installing symfony/orm-pack (v1.0.7): Loading from cacheremote: - Installing symfony/serializer (v4.3.9): Loading from cacheremote: - Installing symfony/property-info (v4.3.9): Loading from cacheremote: - Installing webmozart/assert (1.6.0): Loading from cacheremote: - Installing phpdocumentor/reflection-docblock (4.3.2): Loading from cacheremote: - Installing symfony/serializer-pack (v1.0.2): Loading from cacheremote: - Installing symfony/translation-contracts (v1.1.7): Loading from cacheremote: - Installing symfony/validator (v4.3.9): Loading from cacheremote: - Installing symfony/yaml (v4.3.9): Loading from cacheremote: Package zendframework/zend-eventmanager is abandoned, you should avoid using it. Use laminas/laminas-eventmanager instead.remote: Package zendframework/zend-code is abandoned, you should avoid using it. Use laminas/laminas-code instead.remote: Generating optimized autoload filesremote: Deprecation Notice: Class FOS\RestBundle\Examples\RssHandler located in ./vendor/friendsofsymfony/rest-bundle/Resources/doc/examples/RssHandler.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///tmp/build_cf339a6abd921797e6f08d60cb51e78d/.heroku/php/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:201remote: ocramius/package-versions: Generating version class...remote: ocramius/package-versions: ...done generating version classremote: Executing script cache:clear [KO]remote: [KO]remote: Script cache:clear returned with error code 255remote: !! PHP Fatal error: Uncaught Error: Class 'Symfony\Bundle\TwigBundle\TwigBundle' not found in /tmp/build_cf339a6abd921797e6f08d60cb51e78d/src/Kernel.php:23remote: !! Stack trace:remote: !! #0 /tmp/build_cf339a6abd921797e6f08d60cb51e78d/vendor/symfony/http-kernel/Kernel.php(429): App\Kernel->registerBundles()remote: !! #1 /tmp/build_cf339a6abd921797e6f08d60cb51e78d/vendor/symfony/http-kernel/Kernel.php(130): Symfony\Component\HttpKernel\Kernel->initializeBundles()remote: !! #2 /tmp/build_cf339a6abd921797e6f08d60cb51e78d/vendor/symfony/framework-bundle/Console/Application.php(159): Symfony\Component\HttpKernel\Kernel->boot()remote: !! #3 /tmp/build_cf339a6abd921797e6f08d60cb51e78d/vendor/symfony/framework-bundle/Console/Application.php(65): Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands()remote: !! #4 /tmp/build_cf339a6abd921797e6f08d60cb51e78d/vendor/symfony/console/Application.php(149): Symfony\Bundle\FrameworkBundle\Console\Application->doRun()remote: !! #5 /tmp/build_cf339a6abd921797e6f08d60cb51e78d/bin/console(42): Symfony\Component\Console\Application->run()remote: !! #6 {main}remote: !! t in /tmp/build_cf339a6abd921797e6f08d60cb51e78d/src/Kernel.php on line 23remote: !!remote: Script @auto-scripts was called via post-install-cmdremote: ! WARNING: There was a class not found error in your coderemote:remote: ! ERROR: Dependency installation failed!remote: !remote: ! The 'composer install' process failed with an error. The causeremote: ! may be the download or installation of packages, or a pre- orremote: ! post-install hook (e.g. a 'post-install-cmd' item in 'scripts')remote: ! in your 'composer.json'.remote: !remote: ! Typical error cases are out-of-date or missing parts of code,remote: ! timeouts when making external connections, or memory limits.remote: !remote: ! Check the above error output closely to determine the cause ofremote: ! the problem, ensure the code you're pushing is functioningremote: ! properly, and that all local changes are committed correctly.remote: !remote: ! For more information on builds for PHP on Heroku, refer toremote: ! https://devcenter.heroku.com/articles/php-supportremote: !remote: ! REMINDER: the following warnings were emitted during the build;remote: ! check the details above, as they may be related to this error:remote: ! - There was a class not found error in your coderemote:remote: ! Push rejected, failed to compile PHP app.remote:remote: ! Push failedremote: Verifying deploy...remote:remote: ! Push rejected to agro-interest.remote:To https://git.heroku.com/agro-interest.git ! [remote rejected] master -> master (pre-receive hook declined)error: failed to push some refs to 'https://git.heroku.com/show-agro-interest.git'
Can anyone give me any solution or suggestion? Thanks
In a Symfony 5.0 Application I want to add custom logic for cleanup reasons when the user loggs out.What I have currenty is what is described in the docs:
https://symfony.com/doc/current/security.html#logging-out
As the logout() function in the SecurityController is intercepted by Symfony it won't work to add logic there.
So - where CAN I add logic which is allways executed when a user loggs out?Couldn't find anything in the docs so far...
I have an entity with simple fields. Unfortunately, I can't say what are the validation constraint on the Symfony side. I must post these information on an API route. If it returns no error message, I can validate the entity, if not, I have to display the error messages to the user.
If I want to do it dirty, it's quite easy but I would like to use the Validator.
When I do the $form->isValid
, I would like to have this API call done and add the error messages directly to the form.
At the moment I have something like
if ($form->isSubmitted() && $form->isValid()) { if ($entityModelManager->validate($form)) { //the entity is valid here }}
But as I said, I think this is dirty, I would like to have a better code.
For few months I started to work on a project,I hosted it on ionos. I started my development and put it to the server in test
environnement to make it appear on test.mydomain.fr. The env file I used for test
environnement was .env.test
and contained :
DATABASE_URL=mysql://dbu122774:hY-Dgc*Dpf@db5000327998.hosting-data.io:3306/dbs319817
I use deployer to deploy my website and everything was fine when I tried to deploy to test.
Today I wanted to deploy to the prod environnement www.mydomain.fr. So I create a .env.prod
with :
DATABASE_URL=mysql://dbu448122:sKz737in$Fx2@db5007852583.hosting-data.io:3306/dbs582920
And I set in .env
, APP_ENV
to prod. I start deploying on my prod server, every thing work fine, vendor are successfully installed but after asset are installed a cache:clear
seams to be made and there it throw an error :
[www.mydomain.fr] < In AbstractMySQLDriver.php line 93: An exception occurred in driver:
SQLSTATE[HY000] [1045] Access denied for user 'dbu444942'@'infong-eu146.clienthosting.eu' (using password: YES)
It's really strange because I am 99% sure to have the good host (taken from my admin page of my host company), I tried to change my db password but still the same error.
To be sure I tried to set APP_ENV
to prod in local and run php composer.phar install
and it throws an error in the same AbstractMySQLDriver.php
:
An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Hte inconnu.
When I set APP_ENV
to test (still on my local project) and run the same composer command everything works fine
I don't really know what's happening, I can't find what am I doing wrong...
packages/doctrine.yaml
doctrine: dbal: url: '%env(resolve:DATABASE_URL)%' # IMPORTANT: You MUST configure your server version, # either here or in the DATABASE_URL env var (see .env file) server_version: '5.7' orm: auto_generate_proxy_classes: true naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware auto_mapping: true mappings: App: is_bundle: false type: annotation dir: '%kernel.project_dir%/src/Entity' prefix: 'App\Entity' alias: App
packages/prod/doctrine.yaml
doctrine: orm: auto_generate_proxy_classes: false metadata_cache_driver: type: pool pool: doctrine.system_cache_pool query_cache_driver: type: pool pool: doctrine.system_cache_pool result_cache_driver: type: pool pool: doctrine.result_cache_poolframework: cache: pools: doctrine.result_cache_pool: adapter: cache.app doctrine.system_cache_pool: adapter: cache.system
Thanks