我正在使用Slim框架开发web应用程序。然而,我遇到了一些我无法解决的问题。
我想在类中组织我的代码,并从类中调用某些方法。我有一个index.php文件,其中存在以下函数:
$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
});
我的类代码看起来像这个
class Generate_num
{
public static function generate()
{
//some code
}
}
有什么建议吗?非常感谢。
给定此类:
class Generate_num
{
public static function generate()
{
//some code that creates $number
return $number;
}
}
你这样称呼它:
$number = Generate_num::generate();