Tutorial Saving hero changes does not work #25
-
https://viewi.net/tutorial/step-10 The routing code and Repository method API does not seem to match, so there is an error. In the following code, the first parameter of Router::register('put', '/api/heroes/{id}', function (int $id) {
// read the data
$inputContent = file_get_contents('php://input');
// parse
$stdObject = json_decode($inputContent, false);
// convert type
$hero = JsonMapper::Instantiate(HeroModel::class, $stdObject);
$repository = new Repository(HeroModel::class);
return $repository->Update($id, $hero);
}); But /**
*
* @param int $id
* @param HasId $object
* @return bool
* @throws ReflectionException
*/
public function Update($object)
{
$this->Prepare();
foreach ($this->data as $index => $item) {
if ($item->Id === $object->Id) {
$this->data[$index] = $object;
$this->Flush();
return true;
}
}
return false;
} https://viewi.net/tutorial/step-9 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I've found the repository: |
Beta Was this translation helpful? Give feedback.
-
@kenjis thank you for reporting, I have fixed it, should work now. Please let me know if you have any issue or questions :) |
Beta Was this translation helpful? Give feedback.
@kenjis thank you for reporting, I have fixed it, should work now. Please let me know if you have any issue or questions :)