How to use GET and POST Arguments in Symfony2 - symfony

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.

Related

Using handlebars to filter specific products from a JSON object?

Kind of a weird and specific question but here I go.
I can currently pull all my products through YAML and through some really brute-force methods, I would be able to sort the product out by custom fields.
I have a multiple choice wizard the user has to fill and in the end, I get an object that looks something like this:
{
stoneType: ['Granite', 'Quartz', 'Glass'],
stoneFinish: ['Polished', 'Honed'],
stoneConcern: ['Floor Care'],
labels: ['Daily Cleaning', 'Stain Removal']
}
I can't (or at least I don't know how) to get this data into my HTML to use the data stored in my YAML code and render the specific products.
I believe I can solve this issue if I were able to pass the array of products into javascript using some sort of handlebars helper(?) but Bigcommerce doesn't allow for custom helper functions.
I read online that you can bypass this by installing handlebars but that is not working for me.
When I installed handlebars through NPM, I get this error:
GET http://localhost:3000/stencil/00000000-0000-0000-0000-000000000001/dist/theme-bundle.main.js 404 (Not Found)
Is there a way for me to get custom helper functions working or another possible idea to sort & filter the products?
Thank you, appreciate the help.
EDIT: I have also tried manually downloading Handlebars.js including the file but I get the error Handlebars is not defined. I must be doing something wrong...

Sonata Admin Bundle Search: NonUniqueResultException as Result

When I try to use the search-function in the Sonata Admin Bundle I always get:
An exception has been thrown during the rendering of a template ("The
query returned a row containing multiple columns. Change the query or
use a different result function like getScalarResult().") in
SonataAdminBundle:Core:search.html.twig at line 53.
NonUniqueResultException: The query returned a row containing multiple
columns. Change the query or use a different result function like
getScalarResult().
When I do the search in the productive environment I just get a result if the Admin-Class has no result:
e.g. for Countries (CountryAdmin Class): no result found
I am using sonata-project/admin-bundle (2.3.10)
I tried to reduce my admin-classes to a single one which is very basic - but still having this problems. Any ideas? Thanks...
I had problem with getScalarResult() method, when i did groupBy into my Admin class in createQuery() method.
Maybe it will help
https://groups.google.com/forum/#!topic/sonata-users/cBT09egDtuo
https://github.com/sonata-project/SonataDoctrineORMAdminBundle/issues/297

Symfony2 passed argument is null

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!

Drupal, broken view, need help

I am getting strange problem.
When I am listing some content type, intead of data I am getting 'n/a' string.
I listed views, and on one view I have 'Warning - Broken view!' message.
I can't edit / delete this view because it always redirect to front page.
I checked my logs and all I see is repeating:
# warning: Invalid argument supplied for foreach() in /home/www/testetelgsm/www/includes/common.inc on line 3364.
# warning: Invalid argument supplied for foreach() in /home/www/testetelgsm/www/modules/cck/content.module on line 1284.
# warning: array_keys() [function.array-keys]: The first argument should be an array in /home/www/testetelgsm/www/includes/common.inc on line 3361.
How can I delete / edit this view?
Could somebody help?
Regards
You need to go to the views admin page at: admin/build/views. Here you can find a list of all your views and edit/delete them.
It sounds like you are trying to pull something that doesn't exist anymore like a deleted cck field. Anyways, if it doesn't work to edit it, try to recreate it.
You can make views into features with the features module. That will define the views in a custom module that is generated for you, and make the view defined in code. That will make it possible to restore it, if it gets edited.

Correct way to force an invoice e-mail to be sent to a user in UberCart?

What is the correct way to force the system to send an invoice to a client. I'm trying to use:
uc_order_action_email($order, $settings);
But I keep getting:
Fatal error: Call to undefined function uc_price() in C:\xampp\htdocs\YourEstablishment\src\sites\all\modules\ubercart\payment\uc_payment\uc_payment.module on line 149
It might be a flaw in the module. The function that it's complaining about, uc_price, is defined in
ubercart/uc_store/includes/uc_price.ini
Since it's located in a ini file, that means that drupal wont include it by it self. I'm not familiar with ubercart, since I've never used it, but it seems like this could be a bug in the module. If no one here can come up with an explanation, you should go to the issue tracker.
A quick fix to your problem would be to add this before you call the function
require_once(drupal_get_path('module', 'uc_store') . '/includes/uc_price.inc');
it will include the needed file.

Resources