FatalErrorException: Call to a member function getFirstName() on null - symfony-2.5

Please help me
in C:\xampp\htdocs\project_sms\src\Com\AkSolutions\Sms\UserBundle\Form\Type\UserSendMessageType.php at line 55
$form = $event->getForm();
$form->getData()->setFromUserId($this->user->getId());
$form->getData()->setFromName($this->userProfile->getFirstName()."".$this->userProfile->getLastName());
$form->getData()->setUserType($this->userType);
$form->getData()->setReadStatus(false);
$form->getData()->setDeleteStatus(false);

The problem seems to be here:
$this->userProfile->getFirstName()
specifically the error is telling you that this expression:
$this->userProfile
is null

Related

Laravel doesntHave with callback said object of class Closure could not be converted to string

i want to write a query like that:
$schedule = Schedule::doesntHave('orders', function ($q) {
$q->where('status', Order::STATUS_CANCEL);
})
and laravel throw exception that said:
"Object of class Closure could not be converted to string"
can you help me if you faced this problem?
I find the solution
We should send second parameter to query for can translate query; My query should be like this:
$schedule = Schedule::doesntHave('orders', 'and', function ($q) {
$q->where('status', Order::STATUS_CANCEL);
});

Undefined property: Illuminate\Database\Eloquent\Builder

This strange thing is happening to me.I have the code below :
$state_image =States_Images::where('id_state', $id);
echo $delete_path=$state_image->name;
and the result is :
Undefined property: Illuminate\Database\Eloquent\Builder::$name
Someone help me pls :(
You need to finish the query with get() or first(). In your case probably:
States_Images::where('id_state', $id)->first();

Symfony form validation of integer field

I am trying to use the type validation rule with integer and it fails with some warning.
Here is my form
class BusinessType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('business_number', 'integer', array(
'required' => false,
));
}
}
Here is my validation rule
My\Bundle\Entity\Business:
properties:
business_number:
- Type:
type: integer
So nothing extravagant!
But I get the following error
Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException: "Warning: NumberFormatter::parse(): Number parsing failed"
I already found a work around here, but it doesn't feel right to do that. I will if there is no other solution but I prefer to avoid it.
I know it was a known bug in earlier version of Symfony but it is supposed to be fix. See here.
So is there a way I can use the type validation? And if so, what am I missing?
Edit 1
I am using Symfony 2.6.6
Edit 2
If my value starts with numbers (like 123dd), I have the following error message, even if I customized my error message
This value is not valid.
But if my value starts with something else, I have the error fore-mentioned.
Edit 3
The longest value I need to store is 9 digits long. So integer should work properly.
Edit 4
Here is the bug report
The problem is that the integer and/or number Symfony Form Type utilizes the Symfony\Component\Intl\NumberFormatter\NumberFormatter::parse method before storing the value to the Form. The contents of the method are as such (as of Symfony 2.6.6):
public function parse($value, $type = self::TYPE_DOUBLE, &$position = 0)
{
if ($type == self::TYPE_DEFAULT || $type == self::TYPE_CURRENCY) {
trigger_error(__METHOD__.'(): Unsupported format type '.$type, \E_USER_WARNING);
return false;
}
preg_match('/^([^0-9\-\.]{0,})(.*)/', $value, $matches);
// Any string before the numeric value causes error in the parsing
if (isset($matches[1]) && !empty($matches[1])) {
IntlGlobals::setError(IntlGlobals::U_PARSE_ERROR, 'Number parsing failed');
$this->errorCode = IntlGlobals::getErrorCode();
$this->errorMessage = IntlGlobals::getErrorMessage();
$position = 0;
return false;
}
preg_match('/^[0-9\-\.\,]*/', $value, $matches);
$value = preg_replace('/[^0-9\.\-]/', '', $matches[0]);
$value = $this->convertValueDataType($value, $type);
$position = strlen($matches[0]);
// behave like the intl extension
$this->resetError();
return $value;
}
Notably this part:
preg_match('/^([^0-9\-\.]{0,})(.*)/', $value, $matches);
// Any string before the numeric value causes error in the parsing
if (isset($matches[1]) && !empty($matches[1])) {
IntlGlobals::setError(IntlGlobals::U_PARSE_ERROR, 'Number parsing failed');
// ...
will cause any malformed entry with a string at the start to throw an Exception.
Unfortunately, changing the validation rules will do nothing as this parsing is run before validation occurs.
Your only workaround will be the one you've linked, and to submit a bug report until the problem is fixed. The current master branch doesn't have an update to this file and it's unclear if the problem was solved elsewhere (further research would be required).
Front-end validation could also help (for example, the built-in validation for HTML5 number and integer types will cause most browsers to stop you before submitting to Symfony).

Zend Framework - fetchAll returns fatal error when it has no rows returned?

I know that when I try top use fetchAll and it returns a fatal error, the reason is because it has returned no records on the query. But my question is, how to treat it? How can I know if the query will not return any records, so i do not use toArray()?
For instance,
$table = new Application_Model_Proucts();
$products = $table->fetchAll()->toArray();
How can I do a verification of the query before I put the toArray method?
If there are no records returned from fetchAll() then you are passing nothing to toArray(), which is where the error is occurring.
Try wrapping the last but of your code in an if statement:
$products = $table->fetchAll();
if(count($products))
{
$products = $products->toArray();
}
wrap your query in a condition and/or throw a new exception when condition isn't met

isValid in zend framework form returns FALSE

I have zend framework controller.
In init method i create a form and fill the drop-down box with
$form = new FORM_NAME();
$form->getElement('ZdGroup')->addMultiOptions($zendesk_groups);
then in action i check
$formData = $this->getRequest()->getParams();
if ($form->isValid($formData)) {
...
}
but isValid() returns FALSE
if I delete this line
$form->getElement('ZdGroup')->addMultiOptions($zendesk_groups);
it return TRUE.
I don't understand why, does anybody have an idea?
To answer the question of 'why', have you dumped the form error messages?
$form->getMessages(); //error messages
$form->getErrors(); //error codes
$form->getErrorMessages(); //any custom error messages
That might at least give you a better idea of 'why'.