从 bean 拆箱模型时,RedBean returns 为空?
RedBean returns null when unboxing model from bean?
我无法使 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()
return NULL
?
似乎是命名空间问题。
If you like your models to reside in the namespace \Model, you can set the following constant:
//with namespace Model
define( 'REDBEAN_MODEL_PREFIX', '\Model\' )
You can now create a model class like this:
class \Model\Band extends \RedBeanPHP\SimpleModel { ... }
措辞“...您可以设置...”让我相信它是可选的。然而,事实证明,如果您希望您的模型驻留在命名空间 \Model 中,并且您希望能够使用 FUSE 方法,则您 必须 设置上述常量并且 必须 调用您的模型 class Band
.
另外,请注意,当您定义该命名空间字符串时,您必须在任何地方使用双反斜杠 (\
)。
更让人困惑的是,就在上面的文档段落之前,有一段说
RedBeanPHP automatically connects beans with models using a naming convention (i.e. Model_{TYPE OF BEAN}).
显然,当 不 使用命名空间时,您应该使用命名约定 Model_Band
,而当您这样做时,您应该使用命名约定 Band
,否则事情就会崩溃.
我无法使 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()
return NULL
?
似乎是命名空间问题。
If you like your models to reside in the namespace \Model, you can set the following constant:
//with namespace Model define( 'REDBEAN_MODEL_PREFIX', '\Model\' )
You can now create a model class like this:
class \Model\Band extends \RedBeanPHP\SimpleModel { ... }
措辞“...您可以设置...”让我相信它是可选的。然而,事实证明,如果您希望您的模型驻留在命名空间 \Model 中,并且您希望能够使用 FUSE 方法,则您 必须 设置上述常量并且 必须 调用您的模型 class Band
.
另外,请注意,当您定义该命名空间字符串时,您必须在任何地方使用双反斜杠 (\
)。
更让人困惑的是,就在上面的文档段落之前,有一段说
RedBeanPHP automatically connects beans with models using a naming convention (i.e. Model_{TYPE OF BEAN}).
显然,当 不 使用命名空间时,您应该使用命名约定 Model_Band
,而当您这样做时,您应该使用命名约定 Band
,否则事情就会崩溃.