I am very new to oops in php. Can anyone tell me how can i use a function
我是非常新的oops在PHP中。任何人都可以告诉我如何使用功能
public static function getCategories($id_lang = false, $active = true,$order = true, $sql_filter = '', $sql_sort = '', $sql_limit = '')
{
if (!Validate::isBool($active))
die(Tools::displayError());
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT *
FROM `' . _DB_PREFIX_ . 'category` c
' . Shop::addSqlAssociation('category', 'c') . '
LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON c.`id_category` = cl.`id_category`' . Shop::addSqlRestrictionOnLang('cl') . '
WHERE 1 ' . $sql_filter . ' ' . ($id_lang ? 'AND `id_lang` = ' . (int)$id_lang : '') . '
' . ($active ? 'AND `active` = 1' : '') . '
' . (!$id_lang ? 'GROUP BY c.id_category' : '') . '
' . ($sql_sort != '' ? $sql_sort : 'ORDER BY c.`level_depth` ASC, category_shop.`position` ASC') . '
' . ($sql_limit != '' ? $sql_limit : '')
);
if (!$order)
return $result;
$categories = array();
foreach ($result as $row)
$categories[$row['id_parent']][$row['id_category']]['infos'] = $row;
return $categories;
}
getCategories()
is inside a class named class CategoryCore i want to use this getcategory
into a new class totalDiscount in which a function called configure_products();
getCategories()在一个名为ClassClassCore的类中,我希望将这个getcategory用于一个新类totalDiscount,其中一个函数名为configure_products();
How can i use getcategory()
inside the configure products?
如何在configure产品中使用getcategory()?
2 个解决方案
#1
0
include the class file on the page
在页面上包含类文件
You can create a object of the class inside another class
您可以在另一个类中创建该类的对象
function configure_products(){
$categories = new CategoryCore();
$categories->getcategory();
// use $categories to do stuff
......
.....
}
OR
You can call it directly
你可以直接打电话
function configure_products(){
$categories = CategoryCore::getCategories();
.....
....
}
#2
0
Your function getCategories()
is a static function.
你的函数getCategories()是一个静态函数。
So, it can be called without creating object on teh class CategoryCore
.
因此,可以在不使用类CategoryCore创建对象的情况下调用它。
You can use it as (using scope resolution operator):
您可以将其用作(使用范围解析运算符):
$categories = CategoryCore::getCategories(YOUR_ARGUMENTS)
$ categories = CategoryCore :: getCategories(YOUR_ARGUMENTS)
#1
0
include the class file on the page
在页面上包含类文件
You can create a object of the class inside another class
您可以在另一个类中创建该类的对象
function configure_products(){
$categories = new CategoryCore();
$categories->getcategory();
// use $categories to do stuff
......
.....
}
OR
You can call it directly
你可以直接打电话
function configure_products(){
$categories = CategoryCore::getCategories();
.....
....
}
#2
0
Your function getCategories()
is a static function.
你的函数getCategories()是一个静态函数。
So, it can be called without creating object on teh class CategoryCore
.
因此,可以在不使用类CategoryCore创建对象的情况下调用它。
You can use it as (using scope resolution operator):
您可以将其用作(使用范围解析运算符):
$categories = CategoryCore::getCategories(YOUR_ARGUMENTS)
$ categories = CategoryCore :: getCategories(YOUR_ARGUMENTS)