我正在使用 RedBeanPHP 以及我正在编写的 API 来调用现有数据库。一切都很好,除了一些表的名称中有下划线。根据 RedBean,“类型和属性名称中不允许使用下划线和大写字符。”
在搜索解决方案时,人们推荐使用该功能。
R::setStrictTyping(false);
这将覆盖规则并允许您分配一个 bean,例如
$post_points = R::dispense( 'user_points' );
然而,这在 RedBeanPHP 4KS 中似乎缺失了,因为当我将 SetStringTyping 行放入时,我收到以下错误:
Plugin 'setStrictTyping' does not exist, add this plugin using: R::ext('setStrictTyping')
没有插件。
这个覆盖有解决方法吗? 由于我正在使用现有的数据库模式,因此此时仅更改所有表名以符合 RedBeanPHP 标准并不容易。也不像其他人建议的那样,只是一起切换到不同的系统,例如使用 Doctrine。
最佳答案
找到解决方案。下划线和大写字符的检查只发生在 Facade 中。通过添加此代码:
R::ext('xdispense', function($type){
return R::getRedBean()->dispense( $type);
})
然后您可以无误地执行以下操作。
$post_points = R::xdispense( 'user_points' );
很酷。
关于php - RedBeanPHP 4KS 似乎删除了 R::setStrictTyping(false)。使用下划线分配 bean 的解决方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23019307/