我的扩展 CodeIgniter 2.0.2 类看不到它的父类方法

发布于 2024-11-19 08:02:06 字数 1327 浏览 6 评论 0原文

这是我的第一个 OOP php 应用程序,我在这里有点困惑...

我创建了以下扩展 CI_Model 的类

class LXCoreModel extends CI_Model{

 function __construct() {
         parent::__construct();
}



public function elementExists($table,$row,$data){
     $result = $this->db->select('*')->from($table)->where($row, $data)->get()->result();
     if(empty($result))return false;
     return true;
}
}

,这是扩展上面的类的类:

class LXAccAdminModel extends LXCoreModel{

function __construct()
{
    parent::__construct();
}

function addAccountStatus($statusId=NULL, $username=NULL){
    if($statusId==NULL)$statusId = $this->input->post('accountStatusId');
    if($username==NULL)$username = $this->input->post('username');

    if(elementExists('accounts','username',$username))
            if(elementExists('statuses','id',$statusId))
            {$this->db->insert('accountstatus',array('statusid'=>$statusId,'username'=>$username)); return true;}
    return false;
}
}

两个类都在 Model 目录中,并且类 LXCoreModel是自动加载的(行 $autoload['model'] = array('LXCoreModel'); 存在于 autoload.php 文件中),但是,当我尝试运行我的代码时,我收到此错误:

致命错误:调用未定义 函数 elementExists() 中 C:\wamp\www\CI_APP\application\models\LXAccAdminModel.php 第 25 行

感谢您的宝贵时间! :)

This is my first OOP php app and I'm getting a little stumped here...

I created the following class that extends the CI_Model

class LXCoreModel extends CI_Model{

 function __construct() {
         parent::__construct();
}



public function elementExists($table,$row,$data){
     $result = $this->db->select('*')->from($table)->where($row, $data)->get()->result();
     if(empty($result))return false;
     return true;
}
}

And here is the class extending the class above:

class LXAccAdminModel extends LXCoreModel{

function __construct()
{
    parent::__construct();
}

function addAccountStatus($statusId=NULL, $username=NULL){
    if($statusId==NULL)$statusId = $this->input->post('accountStatusId');
    if($username==NULL)$username = $this->input->post('username');

    if(elementExists('accounts','username',$username))
            if(elementExists('statuses','id',$statusId))
            {$this->db->insert('accountstatus',array('statusid'=>$statusId,'username'=>$username)); return true;}
    return false;
}
}

Both classes are in the Model diretory, and the class LXCoreModel is autoloaded (the line $autoload['model'] = array('LXCoreModel'); exists in the autoload.php file) and yet, when I try to run my code I get this error:

Fatal error: Call to undefined
function elementExists() in
C:\wamp\www\CI_APP\application\models\LXAccAdminModel.php
on line 25

Thanks for your time! :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

合久必婚 2024-11-26 08:02:07

如果我没记错的话,错误就出在你的派生类中,你在调用应该是 $this- 的 elementExists() 函数时忘记了放置 $this 。 >elementExists()

if i am not wrong then the error is in your derived class you have forgot to put $this while calling the elementExists() function that should be $this->elementExists()

真心难拥有 2024-11-26 08:02:06

您正在调用 elementExists(),但不是作为类的方法。

尝试:

$this->elementExists();

或者从LXAccAdminModel

parent::elementExists();

$this->elementExists()在这两种情况下都足够了,$this指的是当前类。

You're calling elementExists(), but not as a method of the class.

Try:

$this->elementExists();

Or from LXAccAdminModel:

parent::elementExists();

$this->elementExists() should suffice in both cases, $this referring to the current class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文