• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cannot use contruct.it gives error in both model and controller

#1
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.