Pergunta

Estou usando Quercus para AppEngine. Tentei salvar uma string php longa (> 1000 caracteres), mas o AppEngine não me permite, pois a string pode conter apenas 500 caracteres. Então eu tentei usar o Datatype de texto do AppEngine. Permite salvar, no entanto, quando recuperar os dados do PHP, ele retorna um tipo de recurso () em vez de string.

Deixe -me explicar com código:

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

Agora está tudo bem e elegante, mas quando eu recuperar o conteúdo de $ E, ele devolverá um recurso () Tipo de dados.

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

Existe alguma solução alternativa para isso? Qualquer ajuda é muito apreciada, pois tenho puxado meu cabelo há dias ...

Foi útil?

Solução

Ok, resolveu -o convertendo o objeto Java em string

$content = $i->getProperty('content');
if(is_object($content)) {
    if($content instanceof Text) {
        $content = $content->getValue();
    }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top