Welcome Guest, Not a member yet? Register   Sign In
trouble calling function in model
#1

(This post was last modified: 01-13-2021, 07:09 PM by richb201.)

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. 
proof that an old dog can learn new tricks
Reply
#2

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 01-13-2021, 07:48 PM by richb201.)

(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? 
proof that an old dog can learn new tricks
Reply
#4

(This post was last modified: 01-14-2021, 07:17 AM by iRedds.)

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
Reply
#5

(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!
proof that an old dog can learn new tricks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB