CakePHP: Editing Data Fields Only

In my data model, I have a field that should be editable only. Ordinary users can edit entries in the model and view this particular field, but they should not edit them. Is there a simple / clean approach for this? I suppose you need to create an additional admin_edit controller action, but what is the best way to "lock" the data field in the controller?

+3
source share
3 answers

You do not need to create a new controller action, but you can do it. Note that you can still use the exact same view using $this->render("edit"): http://book.cakephp.org/view/428/render

I think you should:

  • use the same controller action if this does not confuse users and administrators
  • displays the input field only if the user is an administrator and displays text for other users
  • check authorization in the controller
+2
source

Depending on your installation, this can easily be seen as a validation method in the model. Write a custom function in the model to check if the user has permission.

beforeSave(). , , .

+1

if (hasRoleAdmin) {
 echo $this->Form->input(...);
}
0

Source: https://habr.com/ru/post/1767532/


All Articles