是否有原生的 codeigniter 函数可以用来判断某个模型是否已经加载?可以使用 php 的 class_exists()
判断模型是否已加载吗?
最佳答案
我很想扩展 CI_Loader
核心类。 (参见 extending Core Class)
class MY_Loader extends CI_Loader {
function __construct()
{
parent::__construct();
}
/**
* Returns true if the model with the given name is loaded; false otherwise.
*
* @param string name for the model
* @return bool
*/
public function is_model_loaded($name)
{
return in_array($name, $this->_ci_models, TRUE);
}
}
您将使用以下内容检查给定模型:
$this->load->is_model_loaded('foobar');
That strategy已被 CI_Loader
类使用。
此解决方案支持 CI 的模型命名功能,其中模型的名称可以与模型类本身不同。 class_exists
解决方案不支持该功能,但如果您不重命名模型,应该可以正常工作。
注意:如果您更改了subclass_prefix
配置,它可能不再是MY_
。
关于php - Codeigniter:如何判断模型是否已加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14947220/