コナラを使用してPHPで大きな文字列を保存します
-
26-09-2019 - |
質問
私はAppEngineのためのコナラを使用しています。私は(> 1000文字)を、長いPHPの文字列を保存しようとしたが、文字列のみ500個の文字を保持できるようAppEngineのは私を許可しません。だから私は、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
}
?>
これに任意の回避策はありますか?私は日のために私の髪を引っ張ってきたとして、任意のヘルプは大歓迎です...
解決
[OK]を、文字列にJavaオブジェクトを変換し、それを解決
$content = $i->getProperty('content');
if(is_object($content)) {
if($content instanceof Text) {
$content = $content->getValue();
}
}
所属していません StackOverflow