RedBeanPHP 如何将 bean 包装在已经存在的 table 上?

RedBeanPHP how to wrap bean over already existing table?

我想用 RedBeanPHP 创建 API,我有以下情况: 必须从 table 中找到名称为 "my_data01"

的所有记录
R::findAll( 'my_data01' );

但我的模型 class 的名称为 'Product.php' 其中包含

class Product  extends SimpleModel
{
public $attributes = array();

public function dispense() {}

...//other methods
}

我想以某种方式将我的 table "my_data01" 包裹在 bean 中(可能是) 具有名称产品。 当使用如下代码时:

R::findAll( 'product' );

它将查询 "my_data01" table。 我怎样才能做到这一点?谢谢


还使用了 define( 'REDBEAN_MODEL_PREFIX', 'myapp\' ) 作为当前 bean 的核心负载模型

你不能在 RedBean 中这样做。 ORM 本质上链接到它自己的数据结构。我建议将 my_data01 导入一个名为 product 的新 table。事实上,RedBean 的手册指出:

You should also NOT use RedBeanPHP if you don't like the RedBeanPHP schema policies and you want complete control over the layout of your database schema, i.e. the column names used for primary keys and foreign keys.

当然,您的另一种选择是使用另一个提供更多灵活性的 ORM,例如 Doctrine or Eloquent