简体   繁体   中英

Calling a method form a .class.php file (slim framework)

I am using the Slim framework for the development of a web-app. However, I came across some issues which I can not solve.

I want organize my code in classes and call certain methods from the classes. i have an index.php file in which the following function exists:

$app->post('/',  function () use ($app) {
// some code here
//a variable  $result I want to get the result from a method of the    class Generate_num
$result = (here I want it to take as a result the function "generate"     from a .class.php file which I have stored in a special folder "classes"
 //another code
});

my class code looks like this

class Generate_num
{
public static function generate()
 {
//some code
 }
}

Any suggestions ? Thank you !

Given this class:

class Generate_num
{
    public static function generate()
    {
        //some code that creates $number
        return $number;
    }
}

You call it like this:

$number = Generate_num::generate();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM