1

Implementing service contract using this method getting error of "Class string does not exist."

model/userrepository.php

 public function deletebyid($del)
    {
        $hamburger = $this->hamburger;
        $hamburger->load($del);
        if (! $hamburger->getId())
        {
            throw new NoSuchEntityException(__('Unable to find hamburger with ID "%1"', $del));
        }
         return $hamburger->delete();
    }

api/userrepositoryinterface.php

/**
 * @param int $del
 * @return string
 * @throws \Magento\Framework\Exception\NoSuchEntityException
 */
public function deletebyid($del);

../etc/webapi.xml

  <route method="GET" url="/V1/del/:del">
        <service class="Assign\RestService\Api\HamburgerRepositoryInterface" method="deletebyid"/>
        <resources>
            <resource ref="anonymous"/>
        </resources>

i must be not using delete function properly...but i am not clear.

1

Please update you interface like below.

/**
 * @param int $del
 * @return Assign\RestService\Api\Data\HamburgerInterface
 * @throws \Magento\Framework\Exception\NoSuchEntityException
 */
public function deletebyid($del);

If you want to return any boolean value then just write as @return bool and in other case use any custom or core interface like above in this case your function should return defined type object. Let me know in case further help needed.

| improve this answer | |
  • Hi @asad was my answer helpful for you? – Ramkishan Suthar Nov 22 '18 at 3:37
  • Hi @asad I saw your edit, generally it returns boolean value and it depends on requirement whether you want to returns any object in response or not. – Ramkishan Suthar Nov 22 '18 at 16:28
  • yeah i tried that but "@return Assign\RestService\Api\Data\HamburgerInterface" this return type solve my problem. Even i haven't write any code in this ../Api\Data\HamburgerInterface file but it require this in return – Asad Ullah Nov 22 '18 at 16:29
  • if you write its return type as bool then this function should return any bool value, and in your case if you defines it as any data interface then it should return data interface object. I hope this will clear everythings. – Ramkishan Suthar Nov 22 '18 at 16:32
  • I have updated my answer as well. – Ramkishan Suthar Nov 22 '18 at 16:34

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.