Error in Time to update ZF2 + doctrine - php

People I'm having problem in time to make the edit with the doctrine.
the following error occurs: Fatal error: Call to a member function persist() on a non-object in
below is my code:
public function editAction()
{
$id = $this->params()->fromRoute('id', 0);
$user_update = $this->getEntityManager()->find('CodeDemo\Entity\User', $id);
$user_update->setName('User example');
$user_update->setEmail('user#example.com');
$user_update->setDate(new \DateTime('02/02/02'));
$this->getEntityManager()->persist($user_update);
$this->getEntityManager()->flush();
}
Thank you!!

I solved the problem. Was that the entity manager was null , so giving fatal error!

Related

php 7.0 fatal error Call to undefined method Product::

I try to used to an old customized module in my Prestashop that runs with php 7.0.
I got an error and no idea...
Fatal error: Uncaught Error: Call to undefined method Product::getFrontFeaturesHiddenByNameStatic()
And here is the line of code.
$feature = Product::getFrontFeaturesHiddenByNameStatic((int)($params['cookie']->id_lang), $product['id_product'],'_Descriptif accueil');
And that function is defined in "override" folder.
public static function getFrontFeaturesHiddenByNameStatic($id_lang, $id_product, $featureName) {
self::getFrontFeaturesStatic($id_lang, $id_product);
if( isset(self::$_frontFeaturesCacheHidden[$id_product.'-'.$id_lang]) )
foreach(self::$_frontFeaturesCacheHidden[$id_product.'-'.$id_lang] as $feature) {
if( $featureName == $feature["name"] )
return $feature;
}
return null; // nothing has been found
}
Thanks in advance !
I think I found the solution.
Actually the override definition was not in the right folder.
It was in override/classes and failed, while set in modules/mymodule/override/classes, it seems to work fine...
Thank for your help!

I get error as "Method save does not exist." while updating the data

I want to update the record. I use mongo db and php and I am using laravel 5.4. while updating the data I get the error
BadMethodCallException in Macroable.php line 74:
Method save does not exist.
public function updatedata()
{
$id = DB::connection('mongodb')->collection('login2')->where('_id','=',1)->get();
$id->name = 'Rajesh';
$id->save();
//return $id;
}
This will do the Job! Let me know if it works!
public function updatedata()
{
$id = DB::connection('mongodb')->collection('login2')->where('_id','=',1)->first();
$id->name = 'Rajesh';
$id->save();
//return $id;
}

ZendFramework 2 tutorial Post Title:getTitle() Fatal Error

Everything until now worked perfectly. I'm on page: http://framework.zend.com/manual/current/en/in-depth-guide/understanding-routing.html.
On this page I had to modify 3 files:
-module.config.php
-detail.phtml
-ListController.php
I get the following error:
Post Details
Post Title
Fatal error: Call to a member function getTitle() on null in C:\Program Files\xampp\htdocs\path\to\zf2-tutorial\module\Blog\view\blog\list\detail.phtml on line 6
I didn't paste the code, because it's the same from the link. Can you guys help me figure out my problem?
public function detailAction()
{
$id = $this->params()->fromRoute('id');
try {
$post = $this->postService->findPost($id);
} catch (\InvalidArgumentException $ex) {
return $this->redirect()->toRoute('blog');
}
return new ViewModel(array(
'post' => $post
));
}
Thanks for the update. Now that I see where you are in the tutorial I think you have a problem in the Mapper. See the previous page and chapter Finishing the Mapper
If your mapper cannot find an article it should throw an error as seen in that code example on line 63. Obviously your mapper returns null which causes the error you see Call to a member function getTitle() on null. Because null is not an object after all and doesn't have a getTitle() function.
So have a look at the ZendDbSqlMapper class and the find($id) method and make sure it throws an error if an id isn't found.

Magento Fatal Error - Call to a member function getId() on a non-object

When connecting Magento to Zapier the response is an error code:
authorization failed: junk after document element: line 2, column 0
Further searching shows the cause is an IWD Sales Rep Extension in Magento.
Fatal error: Call to a member function getId() on a non-object in
/home/moove/public_html/app/code/community/IWD/SalesRepresentative/Model/Observer.php
on line 452
Below is line 449 - 459
}
public function getUserSettings(){
$userId = Mage::getModel('admin/session')->getUser()->getId();
$item = Mage::getModel('salesrep/users')->load($userId,'user_id');
if ($item->getId()){
return $item;
}
return false;
}
Appreciate anyone's help resolving this issue.
Try
$userId =Mage::getSingleton('admin/session')->getUser()->getId();

How to Unit Test Type Hint with PHPUnit

I want to test this method:
Class:
public function bind(\Elastica\ResultSet $result = null) {
if (!$result instanceof \Elastica\ResultSet) {
throw new \InvalidArgumentException('I need an instance of \Elastica\ResultSet');
}
$this->bindedData = $result->getResults();
$this->isBinded = true;
}
Test
public function testGetTransformedDataNotSuccesful() {
$this->object->bind(new \stdClass()); //This throws a Catchable fatal error
}
My question is:
How can i test this?
An alternative is not to Type Hint the method var.
Or shouldn't i test this.
Wouldn't it make sense that PHP throws an exception instead of throwing a fatal error ?
Throwing a fatal error is correct, as your method signature explicitly asks for a \Elastica\ResultSet but you provide an \stdClass.
Removing the typehint would also remove the fatal error - but that doesn't make much sense imho :)
edit
This test should pass
public function testGetTransformedDataNotSuccesful() {
$this->setExpectedException(get_class(new PHPUnit_Framework_Error("",0,"",1)));
$this->object->bind(new \stdClass()); //This throws a Catchable fatal error
}

Categories