【问题标题】:Calling a method form a .class.php file (slim framework)从 .class.php 文件调用方法(slim 框架)
【发布时间】:2016-04-10 22:48:19
【问题描述】:

我正在使用 Slim 框架开发网络应用程序。 但是,我遇到了一些我无法解决的问题。

我想在类中组织我的代码并从类中调用某些方法。 我有一个 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
 }
}

有什么建议吗?谢谢!

【问题讨论】:

  • 只是一个友好的提示,您可能需要阅读此页面:The How-To-Ask Guide,这样您就可以始终确保您的问题易于回答且尽可能清晰。请务必包括您为解决遇到的问题所做的任何努力,以及尝试这些修复时发生的情况。也不要忘记您的显示代码和任何错误消息!

标签: php class methods slim


【解决方案1】:

鉴于这个类:

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

你这样称呼它:

$number = Generate_num::generate();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-14
    • 1970-01-01
    • 2016-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-03
    相关资源
    最近更新 更多