support

how to load model from other controller?

Started by huyhoang08, March 15, 2016, 03:54:22 AM

Previous topic - Next topic

huyhoang08

i need to load model from other controller? help me?

yonghan

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.

abantecart

Quote from: huyhoang08 on March 15, 2016, 03:54:22 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.


$this->loadModel('sale/order');
$orders =  $this->model_sale_order->getOrders();


or with generic loader class

$this->load->model('sale/order');
$orders =  $this->model_sale_order->getOrders();



Please  rate your experience or leave your review
We need your help to build better free open source ecommerce platform for everyone. See how you can help

huyhoang08

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?

yonghan

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.

huyhoang08

thank you, i sloved my issue, i think PHP model file should have only _ in file name

Tishbyte

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.

$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?

dvagner

try this:
$that = $this->baseObject;
$that->load->model(....);
$that->model_......

maxter

Quote from: dvagner on February 20, 2019, 01:08:18 AM
try this:
$that = $this->baseObject;
$that->load->model(....);
$that->model_......
If you do this inside of the ext. hook file, it is correct

Tishbyte

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.

yonghan79

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?

Tishbyte

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.


Forum Rules Code of conduct
AbanteCart.com 2010 -