在CodeIgniter HMVC中加载模型时出现错误

3

我在控制器中加载了一个模型,但是出现了以下错误:

消息:未定义的属性:Captcha::$captcha_model

还有这个错误信息:

致命错误:在C:\xampp\htdocs\ci-framework\application\modules\captcha\controllers\captcha.php的第31行调用非对象成员函数captcha_insert()

一切似乎都正确!

控制器:

$time = $captcha['time'];
$ip_address = $this->input->ip_address();
$word = $captcha['word'];
$this->load->model('captcha/captcha_model');
$value = $this->captcha_model->captcha_insert($time, $ip_address, $word);

模型:

class Captcha_model extends CI_model {


 public function captcha_insert($time, $ip_address, $word){

    $query = $this->db->query("insert into captcha
                                (time, ip_address, word)
                                values(?, ?, ?)",
                                array($time, $ip_address, $word));
    if ($query)
        return true;
 }


}

出了什么问题吗? 非常感谢您 :)


1
更改模型名称,然后尝试,也许会起作用。 - Anil Baweja
1
请确保您的模型文件名为Captcha_model.php,并位于application/model/captcha/目录下。 - AdrienXL
@AnilBaweja 谢谢你,但是它没有起作用 :) - Vahid Najafi
@AdrienXL 这是 HMVC,不是 MVC。captcha_model.php 位于 application/modules/captcha/models。非常感谢 :) - Vahid Najafi
@AdrienXL 哎呀,我找到问题了:D 不仅在 module/controller 中,而且在基本的 controller 中,我必须扩展 MX 而不是 CI。谢谢大家。 - Vahid Najafi
显示剩余6条评论
1个回答

0
做这个:
$time = $captcha['time'];
$ip_address = $this->input->ip_address();
$word = $captcha['word'];
$this->load->model('captcha_model/captcha_insert');
$value = $this->captcha_model->captcha_insert($time, $ip_address, $word);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接