我有以下代码:
class Badge extends CI_Model
{
public function foo()
{
echo $this->bar('world');
}
public function bar($word)
{
return $word;
}
}
但它总是给我就行了将错误echo $this->bar('world');
是。
调用未定义的方法(......)
我有以下代码:
class Badge extends CI_Model
{
public function foo()
{
echo $this->bar('world');
}
public function bar($word)
{
return $word;
}
}
但它总是给我就行了将错误echo $this->bar('world');
是。
调用未定义的方法(......)
你不加载你的控制器内部模型:
public function test()
{
$this->load->model('badge');
$this->badge->foo();
}
因为代码的工作 - 我只是测试它使用模型未经编辑粘贴:
class Badge extends CI_Model
{
public function foo()
{
echo $this->bar('world');
}
public function bar($word)
{
return $word;
}
}
输出:
world
为了避免任何外部调用dependecy你需要得到笨实例,并通过调用该实例的方法。
class Badge extends CI_Model
{
public function foo()
{
$CI =& get_instance();
echo $CI->Badge->bar('world');
}
public function bar($word)
{
return $word;
}
}