AbanteCart Community

AbanteCart Development => API Development => Topic started by: huyhoang08 on March 15, 2016, 03:54:22 AM

Title: how to load model from other controller?
Post by: huyhoang08 on March 15, 2016, 03:54:22 AM
i need to load model from other controller? help me?
Title: Re: how to load model from other controller?
Post by: yonghan on March 15, 2016, 07:54:20 AM
Hi, I suggest you to read abantecart core codes both on storefront and admin so you can understand better about calling model etc. You can just use $this->load->model('existing_model'); from your controller.
Title: Re: how to load model from other controller?
Post by: abantecart on March 15, 2016, 08:22:20 AM
i need to load model from other controller? help me?

To load model, you need to include it with below code and you can access methods:
See examples with 'sale/order' model in admin.

Code: [Select]
$this->loadModel('sale/order');
$orders =  $this->model_sale_order->getOrders();

or with generic loader class
Code: [Select]
$this->load->model('sale/order');
$orders =  $this->model_sale_order->getOrders();



Title: Re: how to load model from other controller?
Post by: huyhoang08 on March 15, 2016, 09:48:03 AM
First sory for my english skill.
I cleared about that, But for example:
i have 2 extension activated:
Sory, i mean from one extension i able to load a model belong to other extension?
Title: Re: how to load model from other controller?
Post by: yonghan on March 15, 2016, 10:05:29 AM
You can do that, it's the same as what abantecart says. As long as you know which model that you want to access and use.
Title: Re: how to load model from other controller?
Post by: huyhoang08 on March 15, 2016, 11:10:28 AM
thank you, i sloved my issue, i think PHP model file should have only _ in file name
Title: Re: how to load model from other controller?
Post by: Tishbyte on February 19, 2019, 11:18:08 PM
Hi,
I know this thread is a bit old, but I had a similar question for an extension I am working on.
I am trying to call a function from a different model to delete a product, but as soon as I use that syntax, everything breaks.

Code: [Select]
$this->load->model('catolog/product');
        $this->model_catalog_product->deleteProduct((int)$id);

Error:
load error: AbanteCart core v.1.2.13 Error: Could not load model catolog/product from /home/####/####.com/####/extensions/####/admin/model/catalog/####.php on line 47 in <b>/home/####/####.com/####/core/engine/loader.php</b> on line <b>120</b>

Am I doing something wrong?
Title: Re: how to load model from other controller?
Post by: dvagner on February 20, 2019, 01:08:18 AM
try this:
 $that = $this->baseObject;
 $that->load->model(....);
$that->model_......
Title: Re: how to load model from other controller?
Post by: maxter on February 20, 2019, 07:41:52 AM
try this:
 $that = $this->baseObject;
 $that->load->model(....);
$that->model_......
If you do this inside of the ext. hook file, it is correct
Title: Re: how to load model from other controller?
Post by: Tishbyte on February 20, 2019, 02:35:15 PM
Now I am receiving different errors.
 AbanteCart core v.1.2.13 Call to a member function model() on null in ######


Does anyone know of any useful tutorials for making extensions in Abantecart? The developer's guide provided is very limited.
Title: Re: how to load model from other controller?
Post by: yonghan79 on February 20, 2019, 06:42:16 PM
Hi,

seems you have a typo here:

$this->load->model('catolog/product'); should be $this->load->model('catalog/product');

And are you calling the model from extension hook file or not?
Title: Re: how to load model from other controller?
Post by: Tishbyte on February 28, 2019, 11:58:45 AM
I am not calling from a hook file, but the typo was the issue.
Thank you very much, after looking at the same code for hours I just couldn't see it.
Title: Re: how to load model from other controller?
Post by: yonghan79 on March 01, 2019, 12:49:15 AM
You're welcome