php - 使用 wanwizard datamapper 时调用 codeginiter 帮助程序文件中的模型类对象

标签 php mysql codeigniter-2 datamapper

尝试从 codeigniter 帮助程序文件访问用户类对象时,它抛出类似 Class 'User' not found 的错误。我的代码是这样的 $u = new User(); $u->get(); 我可以在库文件中使用它,但不能在帮助程序文件中使用它。有人可以帮助我吗?

最佳答案

为了在助手中使用模型,您必须:

// Get a reference to the controller object
$CI = get_instance();

// You may need to load the model if it hasn't been pre-loaded
$CI->load->model('User');

// Call a function of the model
$CI->User->get();

希望对你有帮助!

关于php - 使用 wanwizard datamapper 时调用 codeginiter 帮助程序文件中的模型类对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15757638/

相关文章:

php - 表单验证 - 修改 codeigniter 中的第二个参数

php - 如何在 <img> 标签中用 %20 替换空格

php - SQL 请求不按预期工作

php - 在mysql中将日期插入数据库

php - 将 JS 数组传递给 PHP,然后更新 MySQL

php - 无法在 laravel 的数据库中保存文件名

php - 仅当产品存在于 Woocommerce 订单 View 中时才添加订单商品图像

存储在 APC 中的 php 对象删除 mySQL 链接

php - 使用 CodeIgniter 通过查询字符串自定义 URI 路由?

找不到 PhpStorm CodeIgniter 类