Symfony2 passed argument is null - symfony

I'm building a CRM system and I faced a weird problem I'm unable to solve. When I try to create a new CustomerCase entity, I want to assign a CaseState entity for it, so this is what I do in the createAction of CustomerCaseController.php:
$caseStateId = $request->request->get('caseState_id');
$caseState = $this->getDoctrine()->getManager()->getRepository('HSWAshaBundle:CaseState')->findOneById($caseStateId);
$entity = new CustomerCase();
$entity->setCaseState($caseState);
...... etc.....
Everything works just fine until the setCaseState method. After running setCaseState, I get the following error:
Catchable Fatal Error: Argument 1 passed to HSW\AshaBundle\Entity\CustomerCase::setCaseState() must be an instance of HSW\AshaBundle\Entity\CaseState, null given, called in /home/webuser/Symfony/vendor/symfony/symfony/src/Symfony/Component/Form/Util/PropertyPath.php on line 538 and defined in /home/webuser/Symfony/src/HSW/AshaBundle/Entity/CustomerCase.php line 843
The weird part is that $caseState really is a CaseState object (because for example $caseState->getName() works and gives me the correct name for the selected CaseState). For some mind blowing reason it just turns null when I use the setCaseState method. If I do $entity->setCaseState($customerStateObject->getId()), I get the same error message, but this time null changes to integer.
The CustomerCase has a manyToOne relationship with CaseState.
This works just fine if I use the formBuilder's add() method and skip all this manual work, but since I'm using a very specific auto-populating jQuery dropdown for selecting the CaseState from a nested tree structure, I had to manually add the dropdown and read it with $request->request->get().
I've been fighting with this part for almost three days now and would greatly appreciate every help I can get with this!

Finally I got it to work! The reason was $request was missing some parameters because the twig template was missing form_rest(form). After adding that, everything started to work. Thank you!

Related

Symfony Cache TagAwareAdapter problem with saving and then getting cacheItem

Symfony's FilesystemTagAwareAdapter() lets me get, assign a value to, and save a cacheItem, and then retrieve the saved item with another get. But if I also tag the new item before saving, I cannot retrieve the saved item with another get.
when I run the following:
$this->cache = new \Symfony\Component\Cache\Adapter\FilesystemTagAwareAdapter();
$thingItem = $this->cache->getItem('thing');
$thingItem->set('thingValue');
// $thingItem->tag('msc');
$this->cache->save($thingItem);
$retrieved = $this->cache->getItem('thing')->get();
The value of $retrieved is "thingValue".
If I uncomment the "$thingItem->tag('msc');" line and run the code again, the value of $retrieved is null.
I would expect the value of "$retrieved" to be "thingValue" in both cases.
Can anyone explain the inconsistent behavior?
Edit:
This is on php 8.1 and windows 10.
The inconsistent behavior occurs in a phpunit TestCase test in a Symfony project I am working on.
I find that the inconsistent behavior does not occur in a function test using Symfony's KernetTestCase with $this->cache = static::getContainer()->get('cache.app.taggable');
Solved!
It appears that the cache.app.taggable that symfony creates in a Windows environment is not a FilesystemTagAwareAdapter. It is a TagAwareAdapter wrapped around a TraceableAdapter wrapped around a FilesystemAdapter().
So if I create my cache this way:
$this->cache = new TagAwareAdapter(new TraceableAdapter(new FilesystemAdapter());
The code works as expected in a phpunit test!

Stack Trace Error for RefTableId field assignment

I created a new table and added a new Integer field (called RefTableId) with an EDT of the standard RefTableId type. Writing NewTable.RefTableId = tableNum(SomeTable); compiles but during run time I get this stack trace error: "Error executing code: Wrong argument types in variable assignment."
I've even tried NewTable.RefTableId = 0; This still fails. And yes, I've triple checked that it is indeed an integer field.
The solution is really stupid, the line before the assignments was reading .data() out of a FormListItem object that had invalid data in it. Instead of showing an error for that line, it skips over it and fails the assignment lines below. It makes no sense to me since I wasn't using any information from that FormListItem object to populate any field data with, yet still caused that to fail for some reason. I'm going to mark this one in the "Bang Head Here" category.
If the code is in a class, be sure to do a compile of all super classes as well as a compile forward (child classes). Remember to do an incremental CIL.
If it still fails do a full compile (axbuild).

How to use GET and POST Arguments in Symfony2

We are transforming PHP Application to Symfony2 Application.
Most of the pages we are completely writing new but some pages we decided to keep it as it is. i.e I want to use the same php without any major change.
In the php page we used GET['prospect_id'], GET['executive_id'] and many other arguments. Both GET and Post methods. When I view the page in Symfony1.4 there is no error or warning.
But when I view in Symfony 2 I am getting undefined index error.
How can I solve the issue?
EDIT: if GET['prospect_id'] is null there is no error in Symfony 1.4 but i'm getting undefined index notice in Symfony2. There are many variables like that. Is it necessary to define variable before use it. How to avoid this notice message.
What i want is if i am using $_GET['xxx']. symfony2 should not show any notice or error. i want to escape from that.
Use (in Symfony2) the controllers request-object, to get those params:
$this->request->get('prospect_id');
$this->request->get('executive_id');
You can also set default values, if there is no value given. Take a look at this documentation.

Wordpress and FeedBurner Error

I used to use FeedSmith FeedBurner Plugin for my wordpress. Today, suddenly, my feeds are giving following errors under each Post Title. I recently upgrade to WP 3.0.1 but has been a week.
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'Array' was given in /home/name/wordpress/wp-includes/plugin.php on line 166
I deactivated the plugin and install new plugin "FD Feedburner Plugin" and try again but still no luck. The error still persist even on FeedBurner Page.
Any idea please?
Hopefully you have this fixed already. But I'd like to throw some thoughts on this since it remains unanswered. It appears that 50 people have come here since you posted 7 months ago so maybe I can help someone looking to resolve this or a similar problem. My answer is not specific to FeedBurner or even Wordpress.
The call_user_func_array function takes a string or an array as the first parameter and this parameter determines what function/method call will be made. In the case that the first parameter is an array then the method name should actually be the second element of the array and the first element should be the class name that contains the method.
For example:
call_user_func_array(array($class_name, $method_name), $params)
Because your error is saying that "'Array' was given" I can only assume that the first parameter passed to the function is either an empty array, the first parameter is an array with the first element being an empty array, or somewhere earlier in the code the class or function name was converted to a string as an array.
The same error message can result if the first function parameter is an empty array
Both of the following BAD examples will give the "'Array' was given" error:
call_user_func_array(array(), $params);
call_user_func_array(array(array(), 'method_name'), $params);
So if nothing else, you know that first parameter in the call_user_func_array function call is not what it needs to be.
Hope it helps!

filter functions problem

I'm working on a search component for an app I'm working on and I needed to add some filters to it. I've found an example and got the first filter working fine.
Now I'm trying to add a second filter I'm running into problems... In the example I found they use filterFunctions, but I only get an option for filterFunction, why is that?
Here's the example code
productsCollection.filterFunctions =
[
filterByPrice, filterByType,
filterByCondition, filterByVendor
]
And this is what I'm trying
acData.filterFunction = [filterByStatus, filterByDate]
but with this code I get the following error message - 1067: Implicit coercion of a value of type Array to an unrelated type Function.
Why am I getting this error and how would I go about add multiple filters to my Array Collection?
Thanks!
filterFunction must be set to a single function, not an Array or any other datatype. To combine multiple functions create one that combines them, like this:
acData.filterFunction = function(item:Object)
{
return
filterByPrice(item) &&
filterByType(item) &&
filterByCondition(item) &&
filterByVendor(item);
};
If you saw a sample that used filterFunctions plural that accepted an array, post a link. That's not anywhere in the standard Flex framework or in the new 4.0 beta afaik.
It looks like you are going to have to extend an arraycollection to make it work. this link should spell it out for you: http://blog.rotundu.eu/flex/arraycollection-with-multiple-filter-functions/

Resources