php - error updating table field with cakephp -
i have controller in cakephp named adminscontroller. addadmin($id) function,as can see,i try update user's role 'admin',finding him in database using user id (the variable $id).
class adminscontroller extends appcontroller { public $helpers = array('html','form'); var $uses = array('admin', 'user'); public function index() { if(!($this->auth->user('username') && $this->auth->user('role') == 'admin')) { throw new notfoundexception(__('unauthorized access.please login first.')); $this->redirect(array('controller' => 'users','action' => 'login')); } } public function addadmin($id) { $this->loadmodel('user'); $this->user->id = $id; $this->user->set('role','admin'); $this->user->save(); } }
but code not work,though many other cakephp users in stackoverflow have told me way this.. knwo maybe goes wrong or can me in case?
thank in advance!
try this:
public function addadmin($id) { $this->loadmodel('user'); $this->user->id = $id; $this->user->savefield('role','admin'); }
if doesn't work, not getting right id.
Comments
Post a Comment