Is there a way to have an AuthLink to do a delete, so when I click on it it gives me a message to confirm the elimination and if the user doesn’t have permission to delete action it doesn’t appear?
If I understand your question, you just want the behavior of postLink
but only when a user is authorized.
If so:
Simply add logic to control whether the link shows on your UI (or to control what is shown).
//in some template or element
if ($identity->canDelete($entity) {
echo 'code to make your postLink';
}
else {
echo 'whatever you want';
}
That’s correct, but now is giving me an exception: “Call to undefined method Authentication\Identity::canDelete()”, how do I have to define the identity so that it has the candelete function?
I searched for the function canDelete and is not defined anywhere.
Remember that I’m using the cakedc users plugin.
I just wrote that as pseudo-code. In my example $identity->canDelete($entity)
would be replaced by any method you have written to give you a boolean answer to the question.
I sketched the example as it might look if you were using the Authorization plugin and were using Policies.
But the code I provided won’t just work out of the box.