سؤال

أنا أستخدم Quercus لـ AppEngine. حاولت حفظ سلسلة 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
?>

الآن كل شيء على ما يرام و dandy ، ولكن عندما أسترجع محتوى $ e ، فإنه سيعيد لي بيانات من نوع Resource ().

<?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