1084

What is the best location for common methods?

Comments for “What is the best location for common methods?”
 

Posted by mjim on Tuesday 19th April 2022 at 19:32 GMT

I'm using the same method in different controllers and I don't want to repeat myself.

Where would be the best place for custom methods that I can access in all my controllers without changing the code in the core?

For example, I added a logging function which inserts records into the comments table and want to use it in all my controllers.

$this->_log_activity($update_id, 'Updated certificate information.', 'documents', $member_obj->id);
Level One Member

mjim

User Level: Level One Member

Date Joined: 6/01/2022

Posted by Myhiideas on Tuesday 19th April 2022 at 20:57 GMT

Hello,
I would create a module called Custom_Methods and put it all in there.
You call another module with the following code.
Calling another module from a controller:
https://trongate.io/docs_m/information/calling-another-module-from-a-controller
$this->module('module_name');
$this->module_name->do_something();
You call another module with the following code.
Calling another module from a view:
https://trongate.io/docs_m/information/calling-another-module-from-a-view

This comment was edited by Myhiideas on Tuesday 19th April 2022 at 21:01 GMT

Myhiideas

User Level: Guest

Date Joined: 1/11/2021

Posted by mjim on Tuesday 19th April 2022 at 21:03 GMT

That will be perfect. Thank you!
Level One Member

mjim

User Level: Level One Member

Date Joined: 6/01/2022

×