symfony-2.1

embed one form into another symfony2

时光总嘲笑我的痴心妄想 提交于 2019-12-23 05:23:58
问题 I have two entity forms called 'Orders' and 'Address'. I want to embed Address form into orders form. Both entities are having relation by user column. Address Entity class Address { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @ORM\Column(type="string", length=128) */ protected $type; /** * @ORM\ManyToOne(targetEntity="Root\UserBundle\Entity\User", inversedBy="address") * @ORM\JoinColumn(name="user", referencedColumnName="id") *

Symfony2 - Entire child entity in form and Twig template

雨燕双飞 提交于 2019-12-22 11:29:14
问题 In a Sonata admin form, I'd like to display all images related to the current object. Don't need to edit them. I managed to get this working with an entity field type and its property option to select the image URL as label so I can call all pictures in the template : ->add('image', 'entity', array( 'class' => 'Hop\HopBundle\Entity\Image', 'property' => 'image_url', 'query_builder' => function($er) use ($object) { return $er->createQueryBuilder('i') ->where('i.object = :object') -

symfony2 detect locale based on domain name

梦想的初衷 提交于 2019-12-22 10:47:19
问题 i want to setup a new website with 2 locales and the locale should detected by the domain name that's used. Any idea how to do this? for example locales: nl and fr when www.somenldomainname.be is used then the nl locale should be detected when www.somefrdomainname.be is used then the fr locale should be detected it would also be great if i generate an url in nl or fr the right domain name is selected. kind regards, Daan 回答1: You can create an event listener to detect your domain name: class

Symfony 404 not found

末鹿安然 提交于 2019-12-22 10:27:28
问题 I'm new to symfony. I did: rm -rf app/cache/* rm -rf app/logs/* Then: sudo setfacl -R -m u:www-data:rwx -m u:user :rwx app/cache app/logs sudo setfacl -dR -m u:www-data:rwx -m u:user:rwx app/cache app/logs ls -al gives: drwxrwxrwx 3 user user 1024 мая 29 00:06 cache(cache is on green background) drwxrwxrwx 2 user user 1024 мая 29 00:06 logs(logs is on green background) Now i'm trying to access /Symfony/web/app_dev.php - It shows: An error occurred while loading the web debug toolbar (404: Not

Symfony2.1 - The option “em” does not exist when using DataTransformer

杀马特。学长 韩版系。学妹 提交于 2019-12-22 08:26:50
问题 I am using this cookbook recipe to add a data transformer in Symfon 2.1, but I am getting the following error, The option "em" does not exist. Known options are: "attr", "block_name",.... Is this still a valid way to send the entity manager over to the form type? $taskForm = $this->createForm(new TaskType(), $task, array( 'em' => $this->getDoctrine()->getEntityManager(), )); 回答1: While I can't comment if that's the best way or not, I've always passed them to my task constructor as a hard

How to get web directory path from inside Entity?

五迷三道 提交于 2019-12-22 08:09:46
问题 I researched the How to Handle File Uploads with Doctrine and I don't want to hard-code the __DIR__.'/../../../../web/'.$this->getUploadDir(); path because maybe in future I will change the web/ directory. How to do it more flexible? I found this but it doesn't answer the question how to do it more flexible from inside the Entity 回答1: You shouldn't use entity class as a form model here. It's simply not suitable for that job. If the entity has the path property, the only valid values it can

Symfony2 response - Clear cache headers on back button

北城余情 提交于 2019-12-22 05:58:41
问题 I have an issue with clearing my cache when back button is pressed. My header information is saying i'ts loaded from cache: Status Code:200 OK (from cache) My response is set to: $response = new Response; $response->expire(); $response->headers->addCacheControlDirective('must-revalidate', true); $response->headers->addCacheControlDirective('allow_reload', true); What am I doing wrong? None of the documentation methods seem to work... 回答1: Taking advice from this article and setting listed

Symfony forms. File upload

一个人想着一个人 提交于 2019-12-22 00:00:09
问题 Trying to manage file upload with Entity, but i get this error: Fatal error: Call to a member function move() on a non-object in /home/projectpath/src/BS/MyBundle/Entity/Items.php on line 327 Call Stack: 0.0002 333264 1. {main}() /home/projectpath/web/app_dev.php:0 0.0450 1158160... Here's the entity class: namespace BS\BackstretcherBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\Validator\Constraints as Assert; /**

Symfony2 FosUserBundle and SonataUserBundle : overriding entities?

女生的网名这么多〃 提交于 2019-12-21 20:28:16
问题 I use FosUserBundle and SonataUserBundle for my Symfony2 project. I get confused now. I want to add fields for the entity User but it's not working. There is no update for the schema for example. Here is my config : AppKernel: ... new FOS\UserBundle\FOSUserBundle(), new Sonata\UserBundle\SonataUserBundle(), new Application\Sonata\UserBundle\ApplicationSonataUserBundle('FOSUserBundle') config.yml: ... # FOSUserBundle Configuration fos_user: db_driver: orm # BDD type firewall_name: main #

Symfony2 __toString() error

余生颓废 提交于 2019-12-21 17:01:37
问题 I have a problem with saving entities back to me this error: Catchable Fatal Error: Method My\BusinessBundle\Entity\Type::__toString() must return a string value in /var/www/MyBusiness0_1/vendor/doctrine/orm/lib/Doctrine/ORM/ORMInvalidArgumentException.php line 113 The strange thing is that the method __ toString () is the entity Type! class Type { //.. /** * @var string * * @ORM\Column(name="type", type="string", length=100) */ private $type; /** * @ORM\OneToMany(targetEntity="MailTelCont",