Jorge Ferrer Il y a 16 années Very Nice, thanks for sharing this Ray. This post definitely deserves a 5 star Veuillez vous identifier pour voter. Répondre en tant que ... Annuler
Alex Wallace Il y a 16 années Just what I was looking for!Thanks soooo much! Veuillez vous identifier pour voter. Répondre en tant que ... Annuler
Dave Morris Il y a 14 années Here is an updated example that will work with Liferay 5.2.3This example uses the Zend API just because it was what I had available at the time, but the concept applies to any Http client API in PHP or any other language for that matter. The main thing to notice here is that the serviceClassName is different, because ServiceBuilder no longer generates the *ServiceJSON.java files. Also, make sure you add this line to your portal-ext.properties file to allow the json servlet to be accessible from some IP address or hostname: json.servlet.hosts.allowed=localhost,127.0.0.112<?php3require_once ('Zend/Http/Client.php');4require_once ('Zend/Json.php');56$liferay = new Zend_Http_Client();78$liferay->setUri('http://localhost:8080/tunnel-web/secure/json');910// set parameters to return a list of countries from the Liferay db11$liferay->setParameterGet(array(12 'serviceClassName' => 'com.liferay.portal.service.CountryServiceUtil',13 'serviceMethodName' => 'getCountries'14));1516// set authentication17$liferay->setAuth('userid', 'password');1819// send the request20$result = $liferay->request("GET");2122// get back a json response23$json = Zend_Json::decode($result->getBody());2425// print the json object26echo $result->getBody();2728?>And if you're having trouble getting it to work, check out SecureFilter.java, JSONServiceAction.java, and JSONServlet.java to figure out what's going on. Veuillez vous identifier pour voter. Répondre en tant que ... Annuler Dani Danielo Dave Morris Il y a 13 années Hi Dave!i tried your script and it works like a charm, but now i am trying to use the addUser method and dymply don't work.here it is my script:<?phprequire_once ('Zend/Http/Client.php');require_once ('Zend/Json.php'); $liferay = new Zend_Http_Client(); $liferay->setUri('http://localhost:8080/tunnel-web/secure/json');// set parameters to return a list of countries from the Liferay db$liferay->setParameterPost(array( 'serviceClassName' => 'com.liferay.portal.service.UserServiceUtil', 'serviceMethodName' => 'addUser', 'serviceParameters' => 'companyId, autoPassword, password1, password2, screenName, emailAddress, firstName, lastName', //'setFirstName' => 'Pacoooo', 'companyId' => 10112, 'autoPassword' => true, 'password1' => 'pass1', 'password2' => 'pass2', 'screenName' => 'john', 'emailAddress' => 'blah@localhost', 'firstName' => 'John', 'lastName' => 'Doe'/*$liferay->setParameterPost(array( 'serviceClassName' => 'com.liferay.portal.service.CountryServiceUtil', 'serviceMethodName' => 'getCountries'*/));// set authentication$liferay->setAuth('10115', 'password');$result = $liferay->request("POST");// get back a json response$json = Zend_Json::decode($result->getBody());// print the json objectvar_dump($json);?> Veuillez vous identifier pour voter. Répondre en tant que ... Annuler Ray Augé Dani Danielo Il y a 13 années Hmm, I'm not a PHP expert and I can't really see what the problem is. Typically I debug these by using the js console in a Firefox browser first. Then when I know the call works, then I re-code it using the specific language.You could try that (make sure that the /html/js/liferay/service.js is loaded on the page of course and that you are logged into the portal). The calls will look something like:console.log(Liferay.Service.Portal.Country.getCountries());In later versions we switched to async design, so it became:Liferay.Service.Portal.Country.getCountries({}, function(result) {console.log(result)});Note that only methods that are found in the non-Local version of the services can be called. The Local ones are not exposed. Veuillez vous identifier pour voter. Répondre en tant que ... Annuler
Dani Danielo Dave Morris Il y a 13 années Hi Dave!i tried your script and it works like a charm, but now i am trying to use the addUser method and dymply don't work.here it is my script:<?phprequire_once ('Zend/Http/Client.php');require_once ('Zend/Json.php'); $liferay = new Zend_Http_Client(); $liferay->setUri('http://localhost:8080/tunnel-web/secure/json');// set parameters to return a list of countries from the Liferay db$liferay->setParameterPost(array( 'serviceClassName' => 'com.liferay.portal.service.UserServiceUtil', 'serviceMethodName' => 'addUser', 'serviceParameters' => 'companyId, autoPassword, password1, password2, screenName, emailAddress, firstName, lastName', //'setFirstName' => 'Pacoooo', 'companyId' => 10112, 'autoPassword' => true, 'password1' => 'pass1', 'password2' => 'pass2', 'screenName' => 'john', 'emailAddress' => 'blah@localhost', 'firstName' => 'John', 'lastName' => 'Doe'/*$liferay->setParameterPost(array( 'serviceClassName' => 'com.liferay.portal.service.CountryServiceUtil', 'serviceMethodName' => 'getCountries'*/));// set authentication$liferay->setAuth('10115', 'password');$result = $liferay->request("POST");// get back a json response$json = Zend_Json::decode($result->getBody());// print the json objectvar_dump($json);?> Veuillez vous identifier pour voter. Répondre en tant que ... Annuler Ray Augé Dani Danielo Il y a 13 années Hmm, I'm not a PHP expert and I can't really see what the problem is. Typically I debug these by using the js console in a Firefox browser first. Then when I know the call works, then I re-code it using the specific language.You could try that (make sure that the /html/js/liferay/service.js is loaded on the page of course and that you are logged into the portal). The calls will look something like:console.log(Liferay.Service.Portal.Country.getCountries());In later versions we switched to async design, so it became:Liferay.Service.Portal.Country.getCountries({}, function(result) {console.log(result)});Note that only methods that are found in the non-Local version of the services can be called. The Local ones are not exposed. Veuillez vous identifier pour voter. Répondre en tant que ... Annuler
Ray Augé Dani Danielo Il y a 13 années Hmm, I'm not a PHP expert and I can't really see what the problem is. Typically I debug these by using the js console in a Firefox browser first. Then when I know the call works, then I re-code it using the specific language.You could try that (make sure that the /html/js/liferay/service.js is loaded on the page of course and that you are logged into the portal). The calls will look something like:console.log(Liferay.Service.Portal.Country.getCountries());In later versions we switched to async design, so it became:Liferay.Service.Portal.Country.getCountries({}, function(result) {console.log(result)});Note that only methods that are found in the non-Local version of the services can be called. The Local ones are not exposed. Veuillez vous identifier pour voter. Répondre en tant que ... Annuler
Anton Murauyou Il y a 13 années Hi, everyone.Could anyone tell me how can I access other services ( not only in com.liferay.portal.service.spring package as in example? How can I get an article through JSON (for example with com.liferay.portlet.journal.service.spring.JournalArticleServiceUtil?Should I use ServiceBuilder to make this available through JSON?Thanks Veuillez vous identifier pour voter. Répondre en tant que ... Annuler
Gembong Y. Pranolo Il y a 13 années Hi, everyone.I'm a newbie in liferay & I wonder, is there any way to get liferay's session from php ?? please help, need it.Thanks before,Bonks Veuillez vous identifier pour voter. Répondre en tant que ... Annuler Gembong Y. Pranolo Gembong Y. Pranolo Il y a 13 années euh, sorry..Whether this script can be used to retrieve user data using input parameters ?Thanks,Bonks Veuillez vous identifier pour voter. Répondre en tant que ... Annuler
Gembong Y. Pranolo Gembong Y. Pranolo Il y a 13 années euh, sorry..Whether this script can be used to retrieve user data using input parameters ?Thanks,Bonks Veuillez vous identifier pour voter. Répondre en tant que ... Annuler