Author Topic: how to load model from other controller?  (Read 2524 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: 4080
  • Karma: +243/-9
    • 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();



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