我正在使用RedBeanPHP以及我正在编写的API来调用现有数据库.一切都很好,除了一些表在他们的名字中有下划线.根据RedBean的说法,"类型和属性名称中不允许使用下划线和大写字符."
在搜索解决方案时,人们建议使用该功能.
R::setStrictTyping(false);
Run Code Online (Sandbox Code Playgroud)
这将覆盖规则并允许您分配诸如的bean
$post_points = R::dispense( 'user_points' );
Run Code Online (Sandbox Code Playgroud)
但是在RedBeanPHP 4KS中似乎缺少这个,因为当我把SetStringTyping行放入时我收到以下错误:
Plugin 'setStrictTyping' does not exist, add this plugin using: R::ext('setStrictTyping')
Run Code Online (Sandbox Code Playgroud)
这个没有插件.
这种覆盖是否有解决方法?由于我正在使用现有的数据库模式,因此此时只需更改所有表名以符合RedBeanPHP标准就不那么容易了.正如其他人所建议的那样,也不是只使用Doctrine来切换到不同的系统.
找到了解决方案.下划线和大写字符的检查仅发生在Facade中.通过添加此代码:
R::ext('xdispense', function($type){
return R::getRedBean()->dispense( $type);
})
Run Code Online (Sandbox Code Playgroud)
然后,您可以毫无错误地执行以下操作.
$post_points = R::xdispense( 'user_points' );
Run Code Online (Sandbox Code Playgroud)
凉.
| 归档时间: |
|
| 查看次数: |
1452 次 |
| 最近记录: |