CodeIgniter-模型内的调用方法? [英] CodeIgniter - Call method inside a model?

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

问题描述

我有以下代码:

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 echo $this->bar('world'); is.


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

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

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

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