Codeigniter 4, calling controller method in seeder
P粉875565683
P粉875565683 2023-09-08 13:35:04
0
1
547

Good morning, every body, I'm searching how to call a controller's function in my seeding file.

Account Controller

public function createCompte() {
    //generate an account number
        return $numcompte;
    }
}

planter

public function run(){
    $compteController = new CompteController;
    $numcompte = $this->compteController->createCompte();
    $data_client = [ 
           //other data generate with faker
            'num_cmpte_client' => $numcompte ,
           
        ];
    $id_client = $this->db->table('client')->insert($tab);
 }

P粉875565683
P粉875565683

reply all(1)
P粉401901266

As @Pippo pointed out in the comments :

so;

instead of: ❌

$numcompte = $this->compteController->createCompte();

Use this:✅

$numcompte = $compteController->createCompte();

references:

  1. What does the variable $this mean in PHP?
  2. php.net: $this
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template