symfony-2.1

Form: Avoid setting null to non submitted field

自古美人都是妖i 提交于 2019-12-21 05:09:24
问题 I've got a simple model (simplified of source): class Collection { public $page; public $limit; } And a form type: class CollectionType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('page', 'integer'); $builder->add('limit', 'integer'); } public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'data_class' => 'FSC\Common\Rest\Form\Model\Collection', )); } } My controller: public

Updating (from the inverse side) bidirectional many-to-many relationships in Doctrine 2?

走远了吗. 提交于 2019-12-21 02:27:24
问题 Customer is the inverse side of "keywords/customers" relationship with Keyword : /** * @ORM\ManyToMany(targetEntity="Keyword", mappedBy="customers", * cascade={"persist", "remove"} * ) */ protected $keywords; When creating a new customer, one should select one or more keywords. The entity form field is: $form->add($this->factory->createNamed('entity', 'keywords', null, array( 'class' => 'Acme\HelloBundle\Entity\Keyword', 'property' => 'select_label', 'multiple' => true, 'expanded' => true, ))

Fixing requirements in Symfony2

天大地大妈咪最大 提交于 2019-12-20 12:33:38
问题 I've made a Symfony2 installation on my machine. When I check the requirements in my local url: localhost/Symfony2/web/config.php It says: MAJOR PROBLEMS Set the "date.timezone" setting in php.ini* (like Europe/Paris). RECOMMENDATIONS Set short_open_tag to off in php.ini*. Set magic_quotes_gpc to off in php.ini*. Changes to the php.ini file must be done in "/etc/php5/apache2/php.ini". I've made the required changes both in /etc/php5/apache2/php.ini and in /etc/php5/cli/php.ini : date.timezone

How do I force doctrine to reload the data from the database?

霸气de小男生 提交于 2019-12-20 11:48:08
问题 I'm using doctrine/mongodb 1.0.0-BETA1 in a symfony2.1 install. So i'm trying to force my repository to call data from my database instead of using the object it has cached. $audit = $dm->getRepository("WGenSimschoolsBundle:Audit")->findOneById("xxxx"); .... do something somewhere to change the object .... At this point if I call $audit = $dm->getRepository("WGenSimschoolsBundle:Audit")->findOneById("xxxx"); The audit data hasn't changed. It still has the object it originally fetched. If I

Get all errors along with fields the error is connected to

丶灬走出姿态 提交于 2019-12-18 17:25:22
问题 I'm using Symfony2 forms to validate POST and PUT requests to an API. The form handles binding the request data to the underlying entity and then validating the entity. Everything is working pretty well except for collecting errors. I'm using the FOSRestBundle and am throwing a Symfony\Component\HttpKernel\Exception\HttpException with a 400 status code and a message containing the form error messages if validation fails. The FOSRestBundle handles converting this into a JSON response. The

Symfony2.1: Unable to find the controller for path “/login_check”

喜欢而已 提交于 2019-12-17 23:39:01
问题 I used the "Using a traditional login form" tutorial from symfony.com to authentificate my users. With a simple http auth it works great. After the login was submitted I get this Exception: Unable to find the controller for path "/login_check". Maybe you forgot to add the matching route in your routing configuration? Well, in the tutorial I read: You will not need to implement a controller for the /login_check URL as the firewall will automatically catch and process any form submitted to this

How to inject non-default entity managers?

只谈情不闲聊 提交于 2019-12-17 23:25:23
问题 In Symfony2 you can work with multiple entity managers and use something like the code below: $em = $this->get('doctrine')->getManager(); $em = $this->get('doctrine')->getManager('default'); $customerEm = $this->get('doctrine')->getManager('customer'); We can inject the default manager to any service by using: "@doctrine.orm.entity_manager" How can you inject non-default entity managers into services? 回答1: If your entity managers config name is non_default then you can reference it as

Testing Controllers in Symfony2 with Doctrine

落爺英雄遲暮 提交于 2019-12-17 22:37:13
问题 I have created a very simple REST controller in Symony2 with Database insert/updates/deletes in the controller actions. Is there a nice way to write unit/integration tests for these controller actions without polluting the production database? Do I have to work with different environments - or is there a proposed way from the framework vendor for this? Current Controller Example: public function postAction() { $json = $this->getRequest()->getContent(); $params = json_decode($json); $name =

Symfony 2: How do I check if a user is not logged in inside a template?

烂漫一生 提交于 2019-12-17 15:18:50
问题 In Symfony 2 templates (using Twig), how can I effectively check whether a user is not logged in? I don't want to use ROLE checks. I want a straightforward way to check if a user is not logged in. I'm aware that comparing app.user.username with anon works, but that just doesn't feel right to me. 回答1: You can check if app.user is set. {% if app.user %} # user is logged in {% else %} # user is not logged in {% endif %} 回答2: Although the current answer answers the OP's question, I would like to

Symfony throwing ServiceCircularReferenceException

荒凉一梦 提交于 2019-12-13 18:34:21
问题 I am using Symfony 2.7 and i am writing all logs to data based on below tutorial https://nehalist.io/logging-events-to-database-in-symfony/ In service i have monolog.db_handler: class: AppBundle\Util\MonologDBHandler arguments: ['@doctrine.orm.entity_manager'] in monlog db handler i have following class MonologDBHandler extends AbstractProcessingHandler { /** * @var EntityManagerInterface */ protected $em; /** * MonologDBHandler constructor. * @param EntityManagerInterface $em */ public