php - Accessing the username of a user being edited from the model in CakePHP -


from model, how access username of user being edited in cakephp 2.4?

i'm using miles johnson's excellent file uploader userpics in cake 2.4 app, using callback in behavior's actsas config determine name file saved under:

'namecallback' => 'getusername',

which calls following function:

    public function getusername() {     return cakesession::read("auth.user.username"); } 

this works great when it's user editing own picture, comes apart when it's admin editing user: callback returns admin's username, not user's.

the file uploader uploads file , saves under filename , location specified actsas config: in case, i'm having save images under /webroot/img/uploads, using getusername() function username filename. uploader saves file's url in user model under field image.

you can use authcomponent::user('usernane') value if user. http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html

if user assigned role_id or group_id or different type separates admin account try...

if(authcomponent::user('role_id') != 1){ //1 being role assigned admin  return authcomponent::user('username'); } 

see http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html example on role based authentication


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -