CodeIgniter无法从控制器中的模型调用函数 [英] CodeIgniter can't call function from model in controller
本文介绍了CodeIgniter无法从控制器中的模型调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对Codeigniter相当陌生,正尝试从模型中调用一个函数,但无法使其正常工作。有人能看到我在这里做错了吗?
I am fairly new to Codeigniter and am trying to call in a function from my model but I cannot get it to work. Can anyone see what I am doing wrong here?
控制器(farm.php):
Controller (farm.php):
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Farm extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('harvest_first');
}
function harvest()
{
echo $this->harvest_first->harvest();
}
}
模型(harvest_first.php):
Model (harvest_first.php):
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Harvest_first extends CI_Model
{
public function __construct()
{
parent::__construct();
}
public function harvest(){
return "THE FUNCTION";
}
}
?>
我正试图呼应功能,但无论如何我都无法理解
I am trying to echo "THE FUNCTION", but no matter what I do I cannot get it to work as expected.
谢谢,
Simon
Thanks, Simon
推荐答案
尝试一下
class Harvest_first extends CI_Model
更改为:
class Harvest_first_model extends CI_Model
,并在控制器调用中像这样:
and in controller call like this:
$this->load->model('harvest_first_model');
和
$this->harvest_first_model->harvest();
这篇关于CodeIgniter无法从控制器中的模型调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文