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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -