Best way to have some functions in another PHP file

AndyB

Well-known member
What is the best way to put some functions in another PHP file? For example I have an add-on and the Controller file works fine with some functions located near the end of the file. If I wanted to move these functions into another PHP file, how would I call this file? The other PHP file would be in the same directory as the Controller file.

Thank you.
 
My goal is to make a file that is easier to edit by admins.
 
Last edited:
It's not really clear what you're trying to do but rather than editing php files, you should be creating the various options and fields in the ACP and then creating or extending the function as required.

All editing/updating can then be done in the ACP without having to touch the files.
 
It's not really clear what you're trying to do but rather than editing php files, you should be creating the various options and fields in the ACP and then creating or extending the function as required.

All editing/updating can then be done in the ACP without having to touch the files.

This is sound advice, Paul.

Unfortunately some things are just too difficult to create options for. Editing a PHP file is not too difficult as long as the PHP file is fairly short and instructions are well documented.

What I currently have is a ControllerPublic PHP file which has a function in it. I would like to move that function to its own file and have my ControllerPublic PHP file call this External.php file. If I understand correctly I need to create a class and call that class. Perhaps I also have to extend the the ControllerPublic PHP file?
 
I was able to accomplish what I wanted. Here is an example.

(temp1.php)

PHP:
<?php

require_once('temp2.php');

greet('Hello World');

?>

(temp2.php)

PHP:
<?php

function greet($name)
{
    echo $name;
}

?>

When I call temp1.php I get "Hello World" echoed.
 
hm, that's not what i was talking about:d

I was talking about the configuration pattern because i thought that you need it
This is sound advice, Paul.

Unfortunately some things are just too difficult to create options for. Editing a PHP file is not too difficult as long as the PHP file is fairly short and instructions are well documented.

Why would you want to use echo in xenforo?
If you want to output something automatically IN your xenforo template, i would suggest to use the xen:callback or xen:helper feature;)
 
My example in post #7 is just an example of how a function can reside in another file.
 
Back
Top Bottom