我使用应用服务引擎栎。我试图保存长PHP字符串(> 1000个字符),但AppEngine上不会让我作为字符串只能容纳500个字符。所以,我尝试使用AppEngine上的文本数据类型。它让我节省,然而,当我检索PHP数据,它返回我的资源()型的,而不是字符串。

让我代码解释:

<?php
$a = new Text("this is a long string that contains more than 1000 characters");
$b = "this is a long string that contains more than 1000 characters";
$e = new Entity('Article');
$e->setProperty('content', $a); // this works fine
// $e->setProperty('content', $b); // will complain as strlen($b) is > 500
$db = DatastoreServiceFactory::getDatastoreService();
$id = KeyFactory::keyToString($db->put($e)); // works ok, returns the ID of Entity saved
?>

现在所有的罚款和花花公子,但是当我找回$ e的内容,它将返回我的资源()类型的数据。

<?php
$q = new Query('Article');
$ps = $db->prepare($q);
foreach($ps->asIterable() as $i) {
    echo gettype($i->getProperty('content')); // this will echo Object, which when var_dump'd, gives me a resource() which is not convertible to php string, thus I can't get the human readable value
}
?>

有没有解决方法呢?任何帮助是极大的赞赏,因为我一直在拉我的头发天...

有帮助吗?

解决方案

确定解决它通过Java对象转换为字符串

$content = $i->getProperty('content');
if(is_object($content)) {
    if($content instanceof Text) {
        $content = $content->getValue();
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top