我有我的PHP项目中的每个MySQL表的单独的类。类会是这样的:扩展PHP类
class students {
public static function find_all() {
return self::sql_finder("SELECT * FROM ".get_class());
}
}
我用的是同一类的几乎所有我在我的项目表中,除了我更改类名作为表名。现在你可以看到我在类中使用的函数中使用了“get_class()”,所以SQL从类名中获取表名。
因为我有我的所有类使用类太多的功能,我打算与子类这样的扩展类:
class class_with_all_the_common_functions {
public static function find_all() {
return self::sql_finder("SELECT * FROM ".get_class());
}
}
class student extends class_with_all_the_common_functions {
// some table specific functions
}
现在,当我使用student::find_all()
它显示了一个错误:
Database query failed: Table 'dr.class_with_all_the_common_functions
doesn't exist
我想有一点清楚了,我想find_all()
作为其在类学生执行执行。这是通过后期静态绑定可以实现的吗?
您是否尝试过迟的静态绑定? static :: sql_finder()而不是self :: sql_finder()? – Oussama 2012-08-02 14:07:15
嗨Naveen。我可不可以要求你尝试大写'I'并在可能的情况下将代码块/内联格式化?使其尽可能可读可以帮助每个人,包括第一语言不是英语的人。谢谢! – halfer 2012-08-02 14:13:23
嗨halfer,我是新的,事实上这是我的第一个问题,以后生病考虑你的话,谢谢 – 2012-08-03 05:26:02