There is no general “elegant solution” :) I always wanted to do such a thing. Anyway, how could you do this:
Overwrite Html Helper in the application directory - make a copy from /cake/libs/views/helpers/html.php to / app / views / helpers / html.php and made some changes to the Html :: link function.
For example, you can check if the URL contains an action or delete an action.
Another part is to pass the correct parameters from the controller. In AppController :: beforeFilter you can read the user rights (it is better to cache) and pass it to the special Auth variable in the view.
Therefore, when you have rights in your view, it is easy to change the link. :)
As I said, I did not do this in a real example, but so I did.
In this case, there is 1 bad point - if the original Html helper is changed, yours will remain unchanged. But I believe that the Html helper is quite mature, so for me this is not a big problem.
Nik Chankov
source share