Post by revington » Thu Oct 05, 2017 8:27 pm

Hi, I'm writing a new module for opencart 2.3.
This module adds a script to the page, then the script makes an ajax request back to the same controller but different function. Something like:

Code: Select all

class ControllerExtensionModuleTest1 extends Controller {
public function index($setting){ 
//loads a view containing some javascript which will make a POST request back to this controller

public function products(){
}
My first problem is that url 'http://localhost:8000/index.php?route=e ... 1/products' will not hit products($setting). I do need to remove $setting as an argument.
Second problem is that I do not know how to retrieve those settings in a different way.

Also, I've been trying to pass those settings on the url but $this->url->link is converting all "&" into "&" so $this->request->get['param'] does not work.

What I'm doing wrong?

Newbie

Posts

Joined
Thu Sep 28, 2017 5:57 pm

Post by yodapt » Thu Oct 05, 2017 10:44 pm

revington wrote:
Thu Oct 05, 2017 8:27 pm
This module adds a script to the page, then the script makes an ajax request back to the same controller but different function.
This makes no sense.

Anyway, if you want to pass parameters to that controller, you can do it using POST or GET methods. If the & gets translated within the request you can still get the data you passed by replacing & with &.

Opencart Developer - My Extension Showcase
Contact me at aeon.yoda@gmail.com


User avatar
Active Member

Posts

Joined
Fri Jun 17, 2011 6:39 pm


Post by revington » Fri Oct 06, 2017 12:28 am

Hi yodapt,

Thanks for your answer. Why does not make sense? Can you be more elaborate? I'm trying to learn about opencart API and best practices and I find it complex because I can not find documentation so I spend a lot of time reading opencart source code.

So, back to my question. You can call invoke any public function from your controller via http call but I don't understand how do I access my module settings (ones specified at the admin part of the module) also, the controller/index function is always called with $settings but any other function does not.

Is there any way to load those settings?
Also, what is the propper way to invoke $this->url->link function? When this function builds the url transaltes & into & later, when I use that url the controller can not access those params via $this->request->get['something'] because the & thing.
I supose there is a good reason for translating & into & but I can not find it.

Thanks,

Pedro

Newbie

Posts

Joined
Thu Sep 28, 2017 5:57 pm

Post by straightlight » Fri Oct 06, 2017 1:13 am

Followed is a free developed example that already demonstrates how to work with Opencart API by using AJAX request and response with JSON: viewtopic.php?f=24&t=191768

The most generated errors being found on Opencart forum originates from contributed programming.

Regards,
Straightlight


Guru Member
Online

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by revington » Fri Oct 06, 2017 1:41 am

Hi Straightlight,

Thanks for your reply but my problem is different. I want to know how to load module settings from the controller when the controller function is different from index(). Ie POST .... http://localhost:8000/index.php?route=e ... height=100.
The signature of myfunction is public function myfunction() without the $setting variable. Adding $setting to the signature results in a 404. So, if I can not get the settings that way how do I get them?

Newbie

Posts

Joined
Thu Sep 28, 2017 5:57 pm

Post by yodapt » Fri Oct 06, 2017 3:34 am

The settings of a module are available through $this->config->get('desired_key');

Opencart Developer - My Extension Showcase
Contact me at aeon.yoda@gmail.com


User avatar
Active Member

Posts

Joined
Fri Jun 17, 2011 6:39 pm


Post by straightlight » Fri Oct 06, 2017 3:52 am

You can call another controller of any type by using for example:

Code: Select all

$my_module = $this->load->controller('module/my_module');
Assuming the module you're attempting to load would be disabled from the admin and only accessible through your current controller you'd be calling the parent module, you could still acquire that secondary module to your first module. ;)

The most generated errors being found on Opencart forum originates from contributed programming.

Regards,
Straightlight


Guru Member
Online

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 12 guests