Welcome Guest, Not a member yet? Register   Sign In
How to use two models in a controller
#1

Hello everyone, this is about codeigniter 4.

I wanta use two models in a controller. But I have no idea how to solve it. Any suggestion for me please ? 

PHP Code:
<?php namespace App\Controllers;

use 
CodeIgniter\HTTP\IncomingRequest;
use 
CodeIgniter\Controller;
use 
App\Models\CompanyModel;
use 
App\Models\AuthenticationModel;

class 
Login extends BaseController
{   
    
protected $request;
    protected $companyModel;
    protected $authenticationModel;
    
    
public function __construct()
    {
        // Call the Model constructor
        $this->request service('request');
        $this->companyModel = new CompanyModel();
    }

    public function index()
    {
        $data = [
            'name' => $this->companyModel->name()
        ];

        echo view('authentication'$data);
    }

    public function process()
    {
        
        $this
->authenticationModel = new AuthenticationModel();
        $username $this->request->getPost('username');
        $password $this->request->getPost('password');

        $boolen $this->authenticationModel->authentication($username$password);

        return $boolen;
    }

Reply


Messages In This Thread
How to use two models in a controller - by hoffmanchan - 05-11-2020, 02:46 AM



Theme © iAndrew 2016 - Forum software by © MyBB