1084

Get data from another module

Comments for “Get data from another module”
 

Posted by DaddyJohn on Sunday 13th February 2022 at 11:14 GMT

Hi,

I am trying to have the object that is created in a modules manage() method available in a module I have created.

In my new module, I have written a sql query which generates part of the view I want, however for the other part of the view, it seemed efficient if I could just pull in the object that the manage() method when it returns $data['rows]

I have tried using various statements using
$this->module('module_name');
but with no success.
I am sure it is very simple, but the solution is evading me.
Early Adopter

DaddyJohn

User Level: Early Adopter

Date Joined: 23/01/2022

Posted by djnordeen on Sunday 13th February 2022 at 11:37 GMT

Hello,
Your syntax is correct to call another module
$this->module('module_name');

Are you then calling the method name?
$this->module_name->Put your method name here();

The other thing is the method Private, Public..
Dan

This comment was edited by djnordeen on Monday 14th February 2022 at 22:46 GMT

Early Adopter

djnordeen

User Level: Early Adopter

Date Joined: 20/08/2021

Posted by DaddyJohn on Sunday 13th February 2022 at 12:09 GMT

I created a function in my controllers file called index(), where I have got my sql query and passing the data into my view file.
I then wanted to get the date from the module called 'priorities' so I can also pass this to my view file. To try this, I created a new function before the index() function called test(). I will of course make this a private function eventually. If I add the slug /test/ I can see the full /manage/ view - so this is good. But I only want the object $rows , so I can pass this into my view file.

class Homepage extends Trongate {
function test(){
$this->module('priorities');
$rows = $this->priorities->manage();
}

function index(){
$this->module('trongate_security');
$this->trongate_security->_make_sure_allowed();
$sql = ' this is my sql query which I then pass into my view template';
$data['view_module'] = 'homepage';
$data['view_file'] = 'homepage_content';
$this->template('admin', $data);
}
}
Early Adopter

DaddyJohn

User Level: Early Adopter

Date Joined: 23/01/2022

Posted by djnordeen on Sunday 13th February 2022 at 13:11 GMT

class Homepage extends Trongate {
function test(){
$this->module('priorities');
$rows = $this->priorities->manage();
return $rows;
}

function index(){
$this->module('trongate_security');
$this->trongate_security->_make_sure_allowed();
$sql = ' this is my sql query which I then pass into my view template';
$data['view_module'] = 'homepage';
$data['priorities'] = $this->test();   
$data['view_file'] = 'homepage_content';
$this->template('admin', $data);
}
}

This comment was edited by djnordeen on Monday 14th February 2022 at 22:45 GMT

Early Adopter

djnordeen

User Level: Early Adopter

Date Joined: 20/08/2021

Posted by DaddyJohn on Sunday 13th February 2022 at 14:10 GMT

Many thanks,

silly oversight on my part.
Early Adopter

DaddyJohn

User Level: Early Adopter

Date Joined: 23/01/2022

Posted by Myhiideas on Sunday 13th February 2022 at 17:08 GMT

Hit the star button!

Your welcome I do that more often that not

Myhiideas

User Level: Guest

Date Joined: 1/11/2021

Posted by Davcon on Monday 14th February 2022 at 21:13 GMT

Just to let you know, when you're posting code it can look a bit easier on the eyes if you use code tags.

echo 'know what I mean?';
Founding Member

Davcon

User Level: Founding Member

Date Joined: 3/11/2018

×