4

I've written a model object and I cannot edit and save an existing object, a new object is always created. I can create and delete, but editing doesn't work. I'm pretty sure that this is because the "profile_id" parameter isn't in the request when I save the object.

The interesting thing is that the "profile_id" parameter is in the request when I edit an object, it's just not getting passed to my save controller. $profile_id is always 0. Here's the code in my save controller.

$profileId = (int) $this->getRequest()->getParam('profile_id');
        $profile = $this->_profileFactory->create();
        if ($profileId) {
            $profile->load($profileId);
        }
        $this->_coreRegistry->register('profile', $profile);
        return $profile;
  • What is returned by the $this->getRequest()->getParams()? – Siarhey Uchukhlebau May 24 '17 at 14:37
  • getParams() returns everything in the form except the profile_id. (key, active_tab, form_key, name, etc.) – Joseph Hovik May 24 '17 at 14:44
  • In my edit controller, getParams() returns the profile_id and key. – Joseph Hovik May 24 '17 at 14:51
  • For a test, I created the same profile form using a UI component in my layout xml file with a datasource, and saving after editing works. The profile_id is in the request. – Joseph Hovik May 24 '17 at 15:51
  • Do I understand correctly that I don't need to have a datasource for model objects if I use blocks instead of UI components? – Joseph Hovik May 24 '17 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.