Jump to content

Recommended Posts

Posted

 this code on a plugin event 
 

 public function preAction($event)
    { 
Loader::loadModels($this, array("Clients","Companies","ApiKeys","Users"));
   //  $client = $this->Clients->getByUserId(2, true);
    
            $post = [
                'company_id'=>1,
                'user'=>rand(),
                'notes'=>''
            ];
           
        $userKey =  $this->ApiKeys->add($post);
        if (($errors = $this->ApiKeys->errors())) {
            d($errors);
        }
       d( $this->ApiKeys->lastInsertId()); 
}

on refreshing  /admin/settings/system/api/   page  inserts 2 users instead of one

My guess is that preAction event  run twice 

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...