html - How should I edit a model entry in mvc? -


i working on small app using phalcon php framework. have implemented multiple controllers , models, far when want edit user example, use link links

localhost/myappname/user/edit/11 "user's id"

i told not best way this, , trying without passing id through url, using post method in forms without success far. correct way edit or delete entry or there better? tried search problem couldn't figure how name question yet find answered question.

if don't want let access edit page can in few ways.

solution #1

you can use phalcon acl block user's has no permission edit page allowed people managers can edit user or whatever.

see access control lists acl

solution #2

you can crypt/decrypt user id in url not readable humans , in edit method try dectypt id , if not valid echo error.

<?php      use phalcon\crypt;      // create instance     $crypt   = new crypt();      $key     = 'le password';     $user_id = 5;      $encrypt = $crypt->encryptbase64($user_id, $key);     // use $encrypt url <a href="/user/edit/{{encrypt}}">edit</a>      // use decrypt real id of user     $crypt->decryptbase64($encrypt, $key);  ?> 

in way users see url like

localhost/myappname/user/edit/nomgppxd+gaeazap8erf2umtrfl9ghdw1lxvvf39sgkf34afnzok31vdat/owadppj4xgaunclqkrlc/2mfaxq==

for more info see encryption/decryption

but personal opinion is better go acl. after acl made kind of things.

note! if want use encrypt/decript remember wrap decryption in edit method in try/catch block , catch exception don't error if tries guess sone id.

solution #3

if still want using post don't use <a href="...">edit</a> instead can try like:

<form method="post">     <input type="hidden" name="uid" value="{{ user_id }}"/>     <button type="submit">edit</button> </form> 

and in edit method catch id like:

<?php     $user_id = $this->request->getpost("uid"); ?> 

note! in way url not contain user id still can post uid can try hide real user id input type hidden. can use again crypt/decrypt input hidden uid can crypted , decrypt post data in method.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -