0

I have a controller, which calls another controller, and after that a DB call happens, now when i run the DB call it doesn't work, the error i get is

<p>Message:  Undefined property: Advertisement::$admodelobj</p>
<p>Filename: v1/Advertisement.php</p>

This is how my controller looks

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Advertisement extends CI_Controller {


    public function __construct()
    {
        parent::__construct();
    }

    public function getads()
    {   
          //another controller call
          require_once 'application/controllers/v1/ip2locale.php';
            $GetLocale = new ip2locale();
            $range = $GetLocale->index($clientip);
            //now the db call
           $this->load->model('ads_model','admodelobj');            
$campaigns = $this->admodelobj->getCampaigns('desktop',1.00,'IN');
        }
}

Now if i just put the db call above the "Another controller call" it works good, but right after the "another controller call" it gives me the error, what could be the issue?

Brij Raj Singh - MSFT
  • 4,903
  • 7
  • 36
  • 55

2 Answers2

0

Fixed it, one has to load the controller back again to avoid the confusion, and it starts working :)

$ci =& get_instance();          
            $ci->load->model('ads_model','admodelobj');         
            $campaigns = $ci->admodelobj->getCampaigns($deviceTypeValue,$payout,$locale);
Brij Raj Singh - MSFT
  • 4,903
  • 7
  • 36
  • 55
0

Great Brij Raj Singh... Just tell, I have one way :

public function getads(){   
   $this->load->library('../controllers/ip2locale');
   $range = $this->ip2locale->index($clientip);

   .....
}

And it would works :)

Aldi Unanto
  • 3,626
  • 1
  • 22
  • 30