Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

It appears RedBeanPHP 4KS removed R::setStrictTyping(false). What is a workaround for dispensing beans with underscores?

Tags:

php

redbean

I am using RedBeanPHP along with an API I am writing to make calls to an existing Database. Everything works great except some of the tables have underscores in their names. According to RedBean "underscores and uppercase chars are not allowed in type and property names."

When searching for solutions people recommended the use of the function.

R::setStrictTyping(false);

This would override the rules and allow you to dispense a bean such as

$post_points = R::dispense( 'user_points' );

However this appears to be missing in RedBeanPHP 4KS because when I put the SetStringTyping line in I recieve the following error:

Plugin 'setStrictTyping' does not exist, add this plugin using: R::ext('setStrictTyping')

There is no plugin for this.

Is there a workaround for this override? Since I am working with an existing DB schema its not as easy to just change all the table names to conform to RedBeanPHP standards at this point. Nor, as others suggested, just switching to a different system all together such as using Doctrine.

like image 270
tbondt Avatar asked Jan 23 '26 00:01

tbondt


1 Answers

Found out a solution. The check for underscores and uppercase chars only happens in the Facade. By adding this code:

R::ext('xdispense', function($type){
 return R::getRedBean()->dispense( $type);
})

You can then do the following without error.

$post_points = R::xdispense( 'user_points' );

Cool.

like image 77
tbondt Avatar answered Jan 24 '26 21:01

tbondt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!