Use existing classes in prestashop module

隐身守侯 提交于 2020-02-04 22:58:08

问题


I am preparing a custom module for prestashop. I want to use in it some classes that exist in prestashop already (Orderdetail.php).

How can I do this? Is the code below sufficient or do I need to include something else in addition?

$order = new OrderDetail;

回答1:


Yes, the native classes can be called like that.

$order_detail = new OrderDetail();

However to use custom classes you need to include their files in the script you want to use them.

include_once 'path_to_custom_class_file';

class MyModule extends Module {
    public function aMethod() {
        $myClass = new MyClass();
    }
}



回答2:


To make an instance of your module you have to use this code:

$mymodule = Module::getInstanceByName('mycustommodule');

Than you can use method of your module core. E.g.

$mymodule->myCustomMethod('x', 'y');


来源:https://stackoverflow.com/questions/40023358/use-existing-classes-in-prestashop-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!