开发者

My extended CodeIgniter 2.0.2 class doesn't see it's parent class methods

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('LXCoreMod开发者_Python百科el'); 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! :)


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.


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()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜