Domanda

Sto usando quercus per AppEngine. Ho provato a salvare una stringa php lunga (> 1000 caratteri), ma appengine non mi permetterò as String può contenere solo 500 caratteri. Così ho provato ad utilizzare il tipo di dati di testo di AppEngine. Mi permette di risparmiare, però, quando ho recuperare i dati dal PHP, mi restituisce una risorsa () tipo invece di stringa.

Mi spiego con il codice:

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

Ora è tutto bene e dandy, ma quando ho recuperare il contenuto di $ e, mi restituirà una risorsa) tipo di dati (.

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

C'è una soluzione a questo? Ogni aiuto è molto apprezzato come ho tirando i miei capelli per giorni ...

È stato utile?

Soluzione

Ok risolto convertendo oggetto java alla stringa

$content = $i->getProperty('content');
if(is_object($content)) {
    if($content instanceof Text) {
        $content = $content->getValue();
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top