我对Codeigniter相当陌生,正在尝试从我的模型中调用一个函数,但我无法让它工作。谁能看出我在这里做错了什么?
控制器(场.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):
<?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";
}
}
?>
我试图回应"功能",但无论我做什么,我都无法让它按预期工作。
谢谢西蒙
试试这个
class Harvest_first extends CI_Model
更改为 :
class Harvest_first_model extends CI_Model
在控制器调用中,如下所示:
$this->load->model('harvest_first_model');
和
$this->harvest_first_model->harvest();
在这里查看
- 无需在取决于您的模型中添加"_model"
- 只需加载模型并使用它自动加载.php并在那里添加模型,这是一个很好的实践