Page 1 of 1
code design
Posted: Fri Mar 26, 2021 1:52 pm
by loop
Hi Everybody
i'm wondering whats the best way, whenn i want to ad a function to the admin/includes/function.php
i need to add there a function, should i put it there (but thenn on a update it's deleted) should i make a special new database2.php or use override? thank you to help me start coding the right "phoenix-way"
Re: code design
Posted: Fri Mar 26, 2021 2:13 pm
by ecartz
You should put it in your own file, preferably a class file that will be autoloaded.
Re: code design
Posted: Fri Mar 26, 2021 2:16 pm
by loop
if i have a database function i cannot put it in a class file...or do i missunderstand you? i can make like "database2.php" in the /functions folder and in application top i make a include, or you would suggest a other way? (because thenn it's the application top which i changed directly....)
Re: code design
Posted: Fri Mar 26, 2021 2:29 pm
by ecartz
Code: Select all
class my_db_functions {
public static function do_something() {
}
}
If you really must load an include file, you could make a system hook. E.g. includes/hooks/admin/system/include_something.php -- but that won't work in admin until 1.0.8.1 is released.
This is somewhat hard to discuss conceptually, as the approach that one takes depends on the exact circumstances.
Re: code design
Posted: Fri Mar 26, 2021 2:37 pm
by loop
hm okay,..the point is i have a database function which i used very often in my old oscommerce shop and i don't want to rewrite everythin, so it need to be a function (and not your class idea) so at the moment i have to make a new file and a manual include in application top and in 1.0.8.1 i can make then a nice hook insert. looks like this is the only solution
Re: code design
Posted: Fri Mar 26, 2021 4:18 pm
by raiwa
you can use a system hook and put your function outside the class. The system hook will be outo loaded early in application top, so your function will be available without the need to use a include and modify application top.
Or you can use a function file and load it via db system hook.