我的扩展 CodeIgniter 2.0.2 类看不到它的父类方法
这是我的第一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我没记错的话,错误就出在你的派生类中,你在调用应该是
$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 theelementExists()
function that should be$this->elementExists()
您正在调用
elementExists()
,但不是作为类的方法。尝试:
或者从
LXAccAdminModel
:$this->elementExists()
在这两种情况下都足够了,$this
指的是当前类。You're calling
elementExists()
, but not as a method of the class.Try:
Or from
LXAccAdminModel
:$this->elementExists()
should suffice in both cases,$this
referring to the current class.