Bonjour

J'ai une appli développée sous Zend qui expose plusieurs services json qui marchent très bien.

Toutefois un des services me pose problème :

- Si je l'appelle depuis mon navigateur j'obtiens bien la chaine JSON parfaitement formatée.
- Par contre si je l'appelle depuis un autre script PHP avec file_get_contents j'obtiens []

- le file_get_content est bien autorisée car je parviens a appeller les autres services du contrôleur sans difficulté
- si je change le contenu retourné par le service alors il se met à marcher.

Je suis très perplexe.

Le contenu retourné est un tableau associatif :
il contient quelques champs texte plus un champs qui est un tableau
Si je modifie le script pour retourner juste le deuxieme tableau ca marche.

Voici le code de mon action.
Si a la fin je change

Code : Sélectionner tout - Visualiser dans une fenêtre à part
return $response->setBody(Zend_Json::encode($listeexpo));
pour

Code : Sélectionner tout - Visualiser dans une fenêtre à part
return $response->setBody(Zend_Json::encode($listeinscription));
alors l'appel file_get_contents retourne un contenu, alors que dans le premier cas il renvoi []
Dans les deux cas l'appel direct dans le navigateur renvoi un contenu

Voici le détail de l'action dans mon controller

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
public function getexpoAction()
{
	try {
		$request = $this->getRequest();
		$refexpo = $this->_getParam('refexpo', 0);
 
 
		$listeexpo = array();
		$liste = array();
		$listeinscription = array();
 
 
		$mapper = new Application_Model_ExpoVueMapper();
		$mapper = new Application_Model_InscriptionVueMapper();
		$mapperf = new Application_Model_FichierMapper();
 
 
		if ($refexpo>0)  { // recheche pour une expo
			$liste = $mapper->fetchForExpo($refexpo);
			if (isset($liste) && count($liste)>0) {
 
 
				foreach($liste as $inscription)
				{
 
					$fichiers = $mapperf->fetchforInscription($inscription->getId()); // les photos du cataogue;
					$listefichiers=array();
					if (isset($fichiers) && count($fichiers)>0) {
						foreach ($fichiers as $fichier) {
							$listefichiers[]='/photos/'.$fichier->getFilename();
						}
					}
					$listeinscription[]  = array ("idartisan"=>$inscription->getId() ,
							'refpersonne'=>$inscription->getRefpersonne(),
							"nom"=>$inscription->getNom(),
							"prenom"=>utf8_encode(ucfirst(mb_strtolower($inscription->getPrenom()))),
							"denomination"=>ucfirst(strtolower($inscription->getNomcatalogue())),
							"marque"=>$inscription->getMarque(),
							"adresse1"=>$inscription->getAdresse1(),
							"adresse2"=>$inscription->getAdresse2(),
							"adresse3"=>$inscription->getAdresse3(),
							"cp"=>$inscription->getCp(),
							"ville"=>$inscription->getVille(),
							"pays"=>$inscription->getPaysLibelle(),
							"email"=>$inscription->getEmail(),
							"site"=>$inscription->getUrl(),
							"tel"=>$inscription->getTelephone(),
							"fichiers"=>array($listefichiers),
					);
 
				}
			}
 
 
 
 
			if ($refexpo>0) {
				$expo = $mapper->find($refexpo);
 
				if (isset($expo) && $expo->getId()==$refexpo) {	
					$listeexpo = array ("idexpo" => $expo->getId() , "manifestation" => ucfirst(strtolower($expo->getManifestation())), "expo"=>ucfirst(strtolower($expo->getTitre())),"debut"=>$expo->getDatedebut(),"fin"=>$expo->getDatefin(),"lieu"=>ucfirst(strtolower($expo->getLieu())),"nomresp"=>($expo->getPrenom()." ".$expo->getNom()),"telresp"=>$expo->getTelexpo(), "artisans"=>$listeinscription);
				}
			}
		} else {
			$listeexpo = array ("vide");
		}
 
		$this->_helper->layout->disableLayout();
		$this->_helper->viewRenderer->setNoRender(true);
		$response = $this->getResponse();
		$response->setHeader('Content-type', 'application/json', true);
		return $response->setBody(Zend_Json::encode($listeexpo));
		exit;
 
 
 
 
	} catch (Exception $e) {
		Zend_Registry::get("logger")->error(get_class($this)." (". __LINE__.") : ".$e->getMessage());
		$this->_flashMessenger->addError('erreur.erreur');
		$this->_helper->json("");
	}
 
}
voici le code qui appelle le service :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
             $array_expo = file_get_contents('http://localhost/site/getexpo/refexpo/'.$idexpo);
 
             echo $array_expo;  // retourne [] ;-)
 
             // Création du tableau associatif.
             $expo= json_decode($array_expo );
               ....
Je vous remercie d'avance pour vos éclairages.