CodeIgniter Forums
trouble calling function in model - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10)
+--- Thread: trouble calling function in model (/showthread.php?tid=78396)



trouble calling function in model - richb201 - 01-13-2021

In my controller I have this line and the models used in it work fine. 
$this->load->model('MyModel');

For example at one place I call
$this->MyModel->count_qualified_bus_components();  //update the business comps.

I have another module called MyReport. It is a class that extends

class MyReport extends \koolreport\KoolReport
 and it I make a call to My Model. Never mind the crazy KoolReport syntax:


return array(
    "datePicker" => $this->dataStore("campaigns23")->get(0,"taxyear"),
    "BSelect" => $this->MyModel->getTaxyear()
);


The problem is I get this error:

Severity: Notice
Message: Undefined property: MyReport::$MyModel

Filename: assets/MyReport.php
Line Number: 335



So it appears that functions in MyModel are not callable from this second module. How to fix it? I tried adding in
$this->load->model('MyModel'); to the top of the new module, but this didn't work. 


RE: trouble calling function in model - InsiteFX - 01-13-2021

Why do you always use different size font for your problem?

Because of copy and paste.

Some lines cannot even read.

If you have to copy and paste paste it first into a text editor it will change the font to the right size.


RE: trouble calling function in model - richb201 - 01-13-2021

(01-13-2021, 02:52 PM)InsiteFX Wrote: Why do you always use different size font for your problem?

Because of copy and paste.

Some lines cannot even read.

If you have to copy and paste paste it first into a text editor it will change the font to the right size.
Sorry. that is just the font that the error message appeared in. I fixed it now. Back to the question. 
How to get an array into a different module?

Now I just create the data in the controller and shove it into a session variable, thinking I could access the session variable from the koolreport module.

"BSelect" => $this->session->userdata('TY')

But I get this error now: Message: Undefined property: MyReport::$session

How can I use the session in a new module? 


RE: trouble calling function in model - iRedds - 01-14-2021

When you call $this->load->model() or $this->load->library() then the created instance of the class is stored in the global context.
The controller and model have direct access to this store.

Your module most likely does not have the functionality to access the global context

try to do it in your module

PHP Code:
$CI = & get_isntance();
$CI->load->model('MyModel')->library('session');
$this->MyModel $CI->MyModel;
$this->session $CI->session



RE: trouble calling function in model - richb201 - 01-14-2021

(01-14-2021, 07:16 AM)iRedds Wrote: When you call $this->load->model() or $this->load->library() then the created instance of the class is stored in the global context.
The controller and model have direct access to this store.

Your module most likely does not have the functionality to access the global context

try to do it in your module

PHP Code:
$CI = & get_isntance();
$CI->load->model('MyModel')->library('session');
$this->MyModel $CI->MyModel;
$this->session $CI->session
It works! Fantastic. TY!