如何在redbeanphp中使用bindFunc方法?

how to use bindFunc method in redbeanphp?

我正在做一个需要在 mysql 中使用空间对象的项目,我选择 redbeanphp作为本项目中的ORM系统。我发现 redbeanphp 太棒了。 我在 google 中搜索并发现 this link 说 bindFunc 方法可以帮助我使用空间对象,但我找不到任何使用此方法的示例。

这个方法是如何工作的,我该如何使用这个方法?

根据您链接的那个网站的 database 部分:

As of RedBeanPHP 4.1 you can bind an SQL function to a column. This is useful for wrapping values when reading from / writing to the database. For instance, to use MySQL spatial data types you need to prepare the columns like this:

R::bindFunc( 'read', 'location.point', 'asText' );
R::bindFunc( 'write', 'location.point', 'GeomFromText' );

$location = R::dispense( 'location' );
$location->point = 'POINT(14 6)';

//inserts using GeomFromText() function
R::store( $location );

//to unbind a function, pass NULL:
R::bindFunc( 'read', 'location.point', NULL );

添加此函数是为了支持 MySQL 中的空间数据类型,如上所示。文档并不令人惊奇,所以如果您想深入研究,我建议您查看 the source code on Github