controller - access to database from private function in cakephp -
i'm writing private function in cakephp see error: using $this when not in object context think because havent access model , find data private function me please
{ public function blah(){ ... } public function call_remember_me(){ $remembered = remember_me($user_id); }
}
function remember_me($user_id) { $user = $this->user->findbyid($user_id); .... }
assuming using cakephp version 3.x , have connected database in config/app.php, here answer:
if have followed cakephp models , database conventions can use orm (object-relational mapping) table registry method
use cake\orm\tableregistry; // before class declaration $userstable = tableregistry::get('users'); // in function $userdetails = $usertable->get($user_id); // in function
in case have not yet configured config/app.php file establish database connection, kindly [click here][2] more information on how this.
Comments
Post a Comment