PHP对象继承和方法重写
我在CodeIgniter框架中做了一些PHP。我创建了自己的模型类,它扩展并覆盖了默认的codeigniter类。就在下面:PHP对象继承和方法重写,php,oop,codeigniter,inheritance,methods,Php,Oop,Codeigniter,Inheritance,Methods,我在CodeIgniter框架中做了一些PHP。我创建了自己的模型类,它扩展并覆盖了默认的codeigniter类。就在下面: <?php class MY_Model extends CI_Model { public $table; public function __construct() { parent::__construct(); $this->table = get_class($this); $
<?php
class MY_Model extends CI_Model
{
public $table;
public function __construct()
{
parent::__construct();
$this->table = get_class($this);
$this->fields = $this->db->field_data($this->table);
}
}
get_类具有特定的行为:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class TestBase extends CI_Controller{
public function nameWthis(){
return get_class($this);
}
public function nameWOthis(){
return get_class();
}
}
class Test extends TestBase{
public function index()
{
echo $this->nameWthis();
echo '<br/>';
echo $this->nameWOthis();
}
}
使用不带参数的get_class()可以实现静态解析,这可能是您的问题。get_类($this)应该像您所看到的那样工作,动态地返回当前类名
添加代码以检查“语言模型”是否存在。请注意,可能是名称区分大小写,可能会导致失败
最好有错误代码。检查你的日志。在$this->fields=
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class TestBase extends CI_Controller{
public function nameWthis(){
return get_class($this);
}
public function nameWOthis(){
return get_class();
}
}
class Test extends TestBase{
public function index()
{
echo $this->nameWthis();
echo '<br/>';
echo $this->nameWOthis();
}
}
Test
TestBase