Author Topic: how to load model from other controller?  (Read 12615 times)

Offline huyhoang08

  • Newbie
  • *
  • Posts: 25
  • Karma: +1/-1
    • View Profile
how to load model from other controller?
« on: March 15, 2016, 03:54:22 AM »
i need to load model from other controller? help me?

yonghan

  • Guest
Re: how to load model from other controller?
« Reply #1 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.

Offline abantecart

  • Administrator
  • Hero Member
  • *****
  • Posts: 4358
  • Karma: +298/-10
    • View Profile
    • Ideal Open Source Ecommerce Solution
Re: how to load model from other controller?
« Reply #2 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();



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

Offline huyhoang08

  • Newbie
  • *
  • Posts: 25
  • Karma: +1/-1
    • View Profile
Re: how to load model from other controller?
« Reply #3 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?

yonghan

  • Guest
Re: how to load model from other controller?
« Reply #4 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.

Offline huyhoang08

  • Newbie
  • *
  • Posts: 25
  • Karma: +1/-1
    • View Profile
Re: how to load model from other controller?
« Reply #5 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

Offline Tishbyte

  • Newbie
  • *
  • Posts: 38
  • Karma: +7/-0
  • Still Learning
    • View Profile
    • Tishbyte Studios
Re: how to load model from other controller?
« Reply #6 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?

Offline dvagner

  • Core/UI Developer
  • Jr. Member
  • **
  • Posts: 73
  • Karma: +28/-1
    • View Profile
Re: how to load model from other controller?
« Reply #7 on: February 20, 2019, 01:08:18 AM »
try this:
 $that = $this->baseObject;
 $that->load->model(....);
$that->model_......

Offline maxter

  • Full Member
  • ***
  • Posts: 228
  • Karma: +64/-0
    • View Profile
Re: how to load model from other controller?
« Reply #8 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

Offline Tishbyte

  • Newbie
  • *
  • Posts: 38
  • Karma: +7/-0
  • Still Learning
    • View Profile
    • Tishbyte Studios
Re: how to load model from other controller?
« Reply #9 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.

Offline yonghan79

  • Jr. Member
  • **
  • Posts: 56
  • Karma: +17/-0
    • View Profile
Re: how to load model from other controller?
« Reply #10 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?

Offline Tishbyte

  • Newbie
  • *
  • Posts: 38
  • Karma: +7/-0
  • Still Learning
    • View Profile
    • Tishbyte Studios
Re: how to load model from other controller?
« Reply #11 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.

Offline yonghan79

  • Jr. Member
  • **
  • Posts: 56
  • Karma: +17/-0
    • View Profile
Re: how to load model from other controller?
« Reply #12 on: March 01, 2019, 12:49:15 AM »
You're welcome

 

Powered by SMFPacks Social Login Mod