Php 当从bean中取消绑定模型时,RedBean返回null?
我无法让Php 当从bean中取消绑定模型时,RedBean返回null?,php,orm,redbean,Php,Orm,Redbean,我无法让box()方法工作,我只能从中获得NULL 例如,如果我这样做 $bean = \R::load('comment', 2); print("\n\nBEAN:\n"); var_dump($bean); $model = $bean->box(); print("\n\nMODEL:\n"); var_dump($model); 我明白了 BEAN: class RedBeanPHP\OODBBean#68 (10) { protected $properties =
box()
方法工作,我只能从中获得NULL
例如,如果我这样做
$bean = \R::load('comment', 2);
print("\n\nBEAN:\n");
var_dump($bean);
$model = $bean->box();
print("\n\nMODEL:\n");
var_dump($model);
我明白了
BEAN:
class RedBeanPHP\OODBBean#68 (10) {
protected $properties =>
array(4) {
'id' =>
string(1) "2"
'user' =>
string(1) "2"
'reply_to' =>
NULL
'message' =>
string(30) "Test comment 1"
}
protected $__info =>
array(4) {
'type' =>
string(7) "comment"
'sys.id' =>
string(2) "id"
'sys.orig' =>
array(5) {
'id' =>
string(1) "2"
'user' =>
string(1) "1"
'reply_to' =>
NULL
'message' =>
string(30) "Test comment 1"
}
'tainted' =>
bool(false)
'changed' =>
bool(false)
}
protected $beanHelper =>
class RedBeanPHP\BeanHelper\SimpleFacadeBeanHelper#17 (0) {
}
protected $fetchType =>
NULL
protected $withSql =>
string(0) ""
protected $withParams =>
array(0) {
}
protected $aliasName =>
NULL
protected $via =>
NULL
protected $noLoad =>
bool(false)
protected $all =>
bool(false)
}
MODEL:
NULL
显然bean中有数据,那么为什么
box()
返回NULL
?似乎是名称空间问题
报告说
如果希望模型驻留在namespace\Model中,可以设置以下常量:
//with namespace Model
define( 'REDBEAN_MODEL_PREFIX', '\\Model\\' )
现在可以创建如下所示的模型类:
class \Model\Band extends \RedBeanPHP\SimpleModel { ... }
“你可以设置…”这句话让我相信它是可选的。但是,事实证明,如果您希望模型驻留在namespace\Model中,并且希望能够使用FUSE方法,则必须设置上述常量,并且必须调用模型类Band
另外,请注意,定义名称空间字符串时,必须在任何地方使用双反斜杠(\\
)
更让人困惑的是,在上述文件段落之前,有一段说
redbeanppp使用命名约定(即Model_{TYPE OF BEAN})自动将BEAN与模型连接起来
显然,当不使用名称空间时,您应该使用命名约定Model\u Band
,当您使用名称空间时,或者发生故障时,您应该使用命名约定Band