[英]Calling a method form a .class.php file (slim framework)
我正在使用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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.