Welcome Guest, Not a member yet? Register   Sign In
cannot use contruct.it gives error in both model and controller
#1

(This post was last modified: 01-19-2020, 04:24 AM by adil.)

when i use construct in model it give me this error.

ErrorException

Undefined variable: db [url=https://www.google.com/search?q=ErrorException+Undefined+variable%3A+db][/url]


Model:

<?php namespace App\Models;

use CodeIgniter\Model;
use CodeIgniter\Database\ConnectionInterface;

    class My_model extends Model {
protected $db;

public function __construct()
            {
    parent::__construct();
                  $db = \Config\Database::connect();

            }


public function get_allnames() {

        $query = $db->query('SELECT A.* tbl_products');
        $results = $query->getResultArray();
        return $results;
    }

}

Iam i doing it wrong?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB