FAQ Database Discussion Community


Symfony2 Catchable Fatal Error: Argument 1 passed to entity Catchable Fatal Error: Argument 1 passed to entity

php,forms,symfony2,entity,symfony-2.6
I got this error and I'm stuck since many hours Catchable Fatal Error: Argument 1 passed to Thinking\ThinkBundle\Entity\InYourMind::setThinkFriend() must be an instance of Thinking\ThinkBundle\Entity\InYourMindFriend, array given, called in /var/www/html/thinkroulette/vars/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php on line 410 and defined I searched for this issue and lots of results came up but I wasn't capable to...

How to create one log file per session?

symfony2,logging,monolog,symfony-2.6
I want to create for each session an own logfile. I have seen that it is possible to create an own logger (source): use Monolog\Logger; use Monolog\Handler\StreamHandler; // create a log channel $log = new Logger('name'); $log->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING)); // add records to the log $log->addWarning('Foo'); $log->addError('Bar'); Is it possible...

Cache permissions error when deploying with Capifony

symfony2,web-deployment,capifony,symfony-2.6
When I deploy with Capifony a Symfony2 project I get this error message in apache log when accessing a webpage: PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Failed to write cache file "/var/deploys/acme/releases/20150219150638/app/cache/prod/classes.php" In order to avoid this, each time I deploy I have to execute chmod 777 -R...

Join between ManyToMany properties at Doctrine2 entities

php,symfony2,doctrine2,dql,symfony-2.6
I have this tables relationship: This is how my entities for messages and emails looks like (I've just added the important info): class Message { /** * @var Brand * * @ORM\ManyToOne(targetEntity="Brand") * @ORM\JoinColumn(name="brands_id", referencedColumnName="id") */ protected $brand; ... } class Email { /** * @ORM\ManyToMany(targetEntity="Message", inversedBy="messageXrefMail", cascade={"persist", "remove"}) *...

How to set proper JSON response for POST method in RESTful API from FOSRestBundle?

php,json,symfony2,fosrestbundle,symfony-2.6
I am making a POST method for a RESTful API. The API is built on top of FOSRestBundle and NelmioApiDoc as you may notice. I am not able to validate when file is not uploaded or when rid parameter is missing and response with proper JSON. This is what I...

How to correctly instantiate a service from a Command in Symfony2

symfony2,dependency-injection,containers,symfony-2.6
I have a Command in Symfony2 that requires a ProductManager service. I pass two arguments to this service: Doctrine's entity manager and a config array from app/config/config.yml Here is my services.xml in the bundle: <service id="acme.product_manager" class="Acme\ApiBundle\ProductManager" public="true"> <argument>'@doctrine.orm.entity_manager'</argument> <argument>"keys"</argument> </service> Here is the code from the command: protected function...

The show action of Symfony 2 Sonata Admin Bundle is not working

php,symfony2,sonata-admin,symfony-2.6
I'm integrating Sonata Admin Bundle into my Symfony 2.6 application by following Symfony 2 jobeet tutorial. Everything is fine except the Show action. I have an entiry "Job" and so I have src/Ibw/JobeetBundle/Admin/JobAdmin.php which have a function configurShowField(ShowMapper $showMapper) like below <?php namespace Ibw\JobeetBundle\Admin; use Sonata\AdminBundle\Admin\Admin; use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Datagrid\DatagridMapper;...

How to create a console command in Symfony2 application

php,symfony2,symfony-2.6,symfony-components,symfony-console
I need to create a console command for a Symfony2 application and I read docs here and here though I am not sure what of those I should follow. So this is what I did. Create a file under /src/PDI/PDOneBundle/Console/PDOneSyncCommand.php Write this code: namespace PDI\PDOneBundle\Console\Command; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use...

SncRedisBundle not working, what am I doing wrong?

symfony2,redis,symfony-2.6
snc_redis: clients: default: type: predis alias: default dsn: redis://localhost session: client: session prefix: session_ use_as_default: true The above is my current snc_redis config in config.yml I added defined snc_redis as my session handler id by doing the following: framework: ... session: handler_id: snc_redis.session.handler The error I get: The service definition...

Symfony 2.6, pull in other bundle repository, container aware to fixtures

php,symfony2,doctrine,symfony-2.6
I am trying to pull in data from another bundles entity repository in a data fixtures file, to do this i am trying to implement container aware but its not working, is there any way i can run a query on another bundles entity repository from inside a data fixtures...

Catch and upload files from POST call

php,symfony2,symfony-2.6
I am working in a REST Api and I am sending (uploading) a file in a POST. I am working with Symfony 2.6.8 and FOSRestBundle and I am doing this is on the method: /** * Set and upload avatar for reps. * * @param ParamFetcher $paramFetcher * @param Request...

Using Event Subscribers

symfony2,symfony-2.6
I have event subscribers: static public function getSubscribedEvents() { return array( 'event_1' => 'onEvent1', 'event_2' => 'onEvent2', ); } public function onEvent1() { } public function onEvent2() { } it works correctly but I want the listener method onEvent1 worked only after successfully execute event event_1. I know that i...

ServiceNotFoundException: HWIOAuthBundle + Salesforce resource owner

php,symfony2,hwioauthbundle,symfony-2.6
I am trying to get HWIOAuthBundle the bundle installed & configured but I am having some issues. This is what I have done: 1) Enable the bundle at AppKernel.php: new HWI\Bundle\OAuthBundle\HWIOAuthBundle(), 2) Add this line to the config.yml: imports: - { resource: parameters.yml } - { resource: security.yml } -...

FOSRestBundle setup for return JSON but still asking for Twig template

php,json,symfony2,fosrestbundle,symfony-2.6
I have configured FOSRestBundle as following: #FOSRestBundle fos_rest: param_fetcher_listener: true body_listener: true format_listener: rules: - { path: ^/, priorities: [ json, html ], fallback_format: ~, prefer_extension: true } media_type: version_regex: '/(v|version)=(?P<version>[0-9\.]+)/' body_converter: enabled: true validate: true view: mime_types: json: ['application/json', 'application/json;version=1.0', 'application/json;version=1.1'] view_response_listener: 'force' formats: xml: false json: true templating_formats:...

FOSUserBundle + HWIOAuth security configuration failed

php,symfony2,fosuserbundle,hwioauthbundle,symfony-2.6
I'm trying to get FOSUserBundle and HWIOAuth working together for handle the authentication of two types of users: representatives and interns. The representatives ones would begin using HWIOAuth and would use Salesforce and internal FOSUserBundle. I'm trying to set everything but I have problems because Symfony throws this error when...

Logs an entire array using Monolog [closed]

php,symfony2,monolog,symfony-2.6
Is there any way to log an entire array using Monolog? I have been reading several docs but didn't find a way to log the entire array in a readable format, any advice? Docs I've read: Monolog, how to log PHP array into console? http://symfony.com/doc/current/cookbook/logging/monolog.html https://www.webfactory.de/blog/logging-with-monolog-in-symfony2 ...

Add a root element name using JMS Serializer with Symfony 2.6

symfony2,fosrestbundle,jmsserializerbundle,jms-serializer,symfony-2.6
I have implemented web services using Symfony 2.6 with FOSRestBundle and JMSSerializerBundle. I can't manage to have a root element named request eventhough I put xml_root_name: request in the configuration file. I have a config\serializer\Entity.Request.yml file with the following information: Tvjp\RequestBundle\Entity\Request: exclusion_policy: ALL xml_root_name: request properties: id: expose: true type:...

How to write and use Monolog handlers and channels

php,symfony2,monolog,symfony-2.6
I have read some docs here but still not clear to me how to write and use a custom Monolog handler and channel. Let me explain a bit what I want to achieve. I have a custom function and I want that log to be logged into a file called...

Symfony2 dyn. password encoding

php,symfony-2.6
I'm trying to get an own UserBundle to work on sf 2.6.3, using the following guide: Symfony Book. I've pasted that example code in my setPassword method within the user entity (no idea if thats how it's meant to use, though), changing it to fit (see code below). It comes...

How many sessions Symfony app or PHP can manage at same time?

php,symfony2,session,symfony-2.6,symfony-http-foundation
Lets said I have a Symfony2 app that shares two main bundles: OneBundle and TwoBundle. OneBundle acts as a backend for administration purposes and TwoBundle is a RESTful API for externals. Flow for OneBundle is the know for everyone: admin login, do stuff and logout or leave app open or...

Symfony2 error in security.yml

php,symfony2,symfony-2.6
I need help with fixing this error and I am using symfony 2.6 ServiceNotFoundException: The service "fos_user.security.login_manager" has a dependency on a non-existent service "security.context". ...

How to make sure Synfony Entity is loaded to trigger postLoad event?

php,symfony2,symfony-2.6
I'm new to Symfony and following the Jobeet tutorial. I'm trying to inject Container into Entity using service listener and postLoad. The purpose is to use LiipImagineBundle to write a thumbnail image in @ORM\PostPersist. The problem is that the Job entity is not loaded on some routes and then postLoad...

Get file extension after file is uploaded and moved in Symfony2

php,symfony2,symfony-2.6,symfony-http-foundation
I'm uploading a file through Symfony2 and I am trying to rename original in order to avoid override the same file. This is what I am doing: $uploadedFile = $request->files; $uploadPath = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/'; try { $uploadedFile->get('avatar')->move($uploadPath, $uploadedFile->get('avatar')->getClientOriginalName()); } catch (\ Exception $e) { // set error 'can not...

How to retrieve the debug token on exception?

php,symfony2,symfony-2.6
I have written my own ExceptionController and want to inject the debug token as part of the output. I had a look on the WebProfilerToolbarListener, which is similar to my case but it seems that the exception/error response has another lifecycle. The ProfilerCollector is always called after my listener, which...

Rendering Inherit Forms adds extra labels in symfony2

forms,symfony2,twig,symfony-2.6
I've achieved form's data inheritance in symfony2 following documentation, but my problem is when I render it using form_widget() (Twig's function) I'm getting an extra label with the name of the inherit field. Parent Form code: public function buildForm(FormBuilderInterface $builder, array $options){ $builder->add('username') ->add('email', new EmailType()) // <-- Getting child...

Get username in Synfomy (in Twig) on page, which is accessible to anonymous users

php,authentication,twig,symfony-2.6
Is there a way to access username of the logged user on page, which is accessible to anonym users in Symfony 2.6.1? Example: I have main page, where is link to login and if there is a user logged in, I want to display his username as a link to...

More than one firewall at Symfony2 project security.yml, how to deal with pattern?

php,symfony2,fosuserbundle,hwioauthbundle,symfony-2.6
I am working in a project where I will need two firewalls or secured areas. The first firewall/secured area will allow login/logout using HWIOAuthBundle using Salesforce as provider, the second firewall/secured area will allow login/logout through FOSUserBundle since this is for internal sysadmin and so on. I have a doubt...

Symfony open a default page for restricted access

symfony2,authentication,symfony-2.6
How can I redirect automaticaly an user when it enters a restricted page to /register-as-guest? My wrong solution: in security.yml I set firewalls: default: form_login: login_path: /register-as-guest This works, but when user enters wrong credentials at login it is redirected to /register-as-guest ( login_path ) but should be redirected to...

Permanently extend symfony twig template

symfony2,twig,symfony-2.6
In my symfony2 application I created a dashboard which currently consists of many navigation elements. Now I am trying to split those elements into several bundles. This is the code I have: {# app/Resources/views/base.html.twig #} {# ... #} {% block body %} {% endblock %} {# ... #} Then in...

How to change post parameters to json raw format

php,rest,symfony2,fosrestbundle,symfony-2.6
I am using FOSRestBundle for build a Restful API. I have this code for a POST Restful service: /** * Create a new session. * @param ParamFetcher $paramFetcher * * @ApiDoc( * resource = true, * https = true, * description = "Create a new session", * statusCodes = {...

How to remove fields from the admin user create page of Sonata User Bundle?

symfony2,sonata-admin,sonata-user-bundle,symfony-2.6
I have installed Sonata Admin Bundle and User Bundle in my Symfony 2.6 application. I found that the User bundle creates a bundle at src/Application/Sonata/UserBundle. When I go to the admin user creation page (admin/sonata/user/user/create), I found a lot of fields there: General Username E-Mail-Address Plain password Groups Profile Date...

Create new brand from company: embed admin in admin in SonatAdminBundle

php,symfony2,sonata-admin,symfony-sonata,symfony-2.6
I have this two tables (see pics below) mapped as follow: class Brand { ... /** * @var Company * * @ORM\ManyToOne(targetEntity="Company") * @ORM\JoinColumn(name="companies_id", referencedColumnName="id") */ protected $company; } class Company { ... } I have two admin classes: CompanyAdmin and BrandAdmin. I need to add support for add a...

How to get Container object from LifecycleEventArgs of postLoad in Entity?

php,symfony2,entity,containers,symfony-2.6
I'm trying to inject the Container object (which is available in controllers) into an Entity using postLoad lifecycleCallbacks. The argument to the postLoad method is LifecycleEventArgs. I could see the container property (which I want to retrieve) in EventManager of LifecycleEventArgs according to the dump output, but it seems to...

KnpLabs DoctrineBehaviors translatable query count

doctrine2,symfony-2.6
I am using KnpLabs/DoctrineBehaviors translatable. I have a Post entity and a BlogCategory entity. Post.php class Post { use Timestampable; /** * @ManyToMany(targetEntity="BlogCategory") * @JoinTable(name="post_categories") * @var ArrayCollection */ protected $categories; ... } class BlogCategory { use Translatable; /** * @Id() * @GeneratedValue(strategy="AUTO") * @Column(type="integer") * @var int */ private...

Symfony2 - Use Bootstrap (glyphicon) and jQuery

twitter-bootstrap,symfony2,symfony-2.6
I am a beginner with Symfony and I am trying to integrate a specific Bootstrap theme and jQuery. Because of the css files, the js files and the fonts are shared by all the bundles, I put the resources into the app\Resources\public directory. In this directory, I have the following...

How to override others dependencies in composer.json

php,symfony2,composer-php,symfony-2.6
I'm using AliceFixturesBundles and this depends on NelmioAlice and Faker. Dependencies are handled internal as for example: https://github.com/h4cc/AliceFixturesBundle/blob/master/composer.json { "name": "h4cc/alice-fixtures-bundle", "description": "Symfony2 Bundle for loading fixture data with the Alice library.", "keywords": ["Symfony2", "Fixtures", "Alice", "Loader", "Doctrine", "ORM", "MongoDB"], "type": "symfony-bundle", "license": "MIT", "authors": [ { "name": "Julius Beckmann",...

Add brands through company, it's possible? How?

php,symfony2,doctrine2,mapping,symfony-2.6
I have this two tables (see pics below) mapped as follow: class Brand { ... /** * @var Company * * @ORM\ManyToOne(targetEntity="Company") * @ORM\JoinColumn(name="companies_id", referencedColumnName="id") */ protected $company; } class Company { ... } I need to add support for add a new Brand from Company but I have not...

Entity choice list in FormType isn't sending values

symfony2,symfony-2.6
I have the following code in my FormType: /** * @var User */ protected $currentUser; /** * param User $currentUser */ public function __construct($currentUser) { $this->currentUser = $currentUser; } public function buildForm(FormBuilderInterface $builder, array $options) { $currentUser = $this->currentUser; $builder ->add('breedingPairMale', 'entity', array( 'class' => 'Breedr\GeckoBundle\Entity\Gecko', 'property' => 'id', 'property'...