代码Igniter - 模型中的调用方法? [英] Code Igniter - Call method inside a model?

查看:171
本文介绍了代码Igniter - 模型中的调用方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

class Badge extends CI_Model
{
    public function foo()
    {
        echo $this->bar('world');
    }

    public function bar($word)
    {
        return $word;
    }
}

但它总是给我一个错误 echo $ this-> bar('world');

But it always gives me an error on the line where is echo $this->bar('world');


调用未定义的方法...)

Call to undefined method (......)


推荐答案



Your not loading your model inside your controller:

public function test()
    {
        $this->load->model('badge');
        $this->badge->foo();
    }

因为代码工作 - 我刚刚通过使用你的模型未编辑:

Because the code works - I've just tested it by pasting using your model unedited:

class Badge extends CI_Model
{
    public function foo()
    {
        echo $this->bar('world');
    }

    public function bar($word)
    {
        return $word;
    }
}

输出:

world

这篇关于代码Igniter - 模型中的调用方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆