This my first soap code in PHP.
But I dont get any result. I think there is some problems in soapCall and SoapClient.
I have three file.
server , client and service.
I want to connect to server and just get students name by soap. This is so simple code but doesnt work.
//server.php
<?php
class server
{
public function __construct()
{
}
public function getStudentsName($id_array)
{
return 'Mohammad';
}
}
$params = array('uri'=>'phpsoap/server.php');
$server = new SoapServer(NULL , $params);
$server -> setClass('server');
$server -> handle();
?>
//client.php
<?php
class client
{
public function __construct()
{
$params = array('location' => 'http://phpsoap.exp/server.php',
'uri' => 'urn://phpsoap/server.php',
'trace' => 1
);
$this->instance= new SoapClient(NULL , $params);
}
public function getName($id_array)
{
$this->instance->__soapCall('getStudentsName' , $id_array);
}
}
$client = new client;
?>
//service.php
<?php
include './client.php';
$id_array=array('id'=>'1');
echo $client->getName($id_array);
?>
Method client::getName should return value from __soapCall, currently is return void, that's why you don't see anything
public function getName($id_array)
{
return $this->instance->__soapCall('getStudentsName' , $id_array);
}
Related
I am a beginner in php. I have a WadoService service and a StudiesRestController controller. I want to use controller data in the service.
public function getPatientAction(Request $request, $studyUID)
{
$studyRepository = new StudyRepository(
$this->get('nexus_db'),
$this->get('logger'),
$this->get('translator')
);
$study = $studyRepository->getStudy($studyUID);
if (!$study) {
throw new NotFoundHttpException("No study found with studyuid $studyUID");
}
$patientInfo = new RestResponse(
SerializerBuilder::create()
->build()
->serialize($study->getPatient(), 'json')
);
return $patientInfo;
}
Is this possible? I have tried to put this in the function getPatientAction()without result:
/* #var $wadoService WadoService */
$wadoService = $this->container->get(WadoService::SERVICE_NAME);
$wadoService = new RestResponse(
SerializerBuilder::create()
->build()
->serialize($study->getPatient(), 'json')
);
To pass a variable from your controller to your service, you do it it like that :
$wadoService = $this->container->get(WadoService::SERVICE_NAME)->yourServiceMethod($yourVari);
I want to send sms for registration users.
my sms getway provider using SOAP to connect users to api.
this is how code works:
function sendSMS($mobile, $text){
ini_set("soap.wsdl_cache_enabled", "0");
$value = array('MY USER', 'My pass', 'my sms server number', user mobile number, $text, '1');
$url = 'http://mysmsmprovider.com/WebService/V4/BoxService.asmx?wsdl';
$method = 'SendMessage';
$param = array('Username' => "$value[0]",'Password' => "$value[1]",'Number' => "$value[2]",'Mobile' => array("$value[3]"),'Message' => "$value[4]",'Type' => "$value[5]");
define($security,1);
require_once ("connection.php");
$request = new connection($url,$method,$param);
$message = $request->connect();
$request->__destruct();
unset($value,$url,$method,$param,$request);
if ($message == 'Send Successfully'){
return 1;
}else{
return 0;
}
}
now the connection.php file contents:
<?php
if(!defined($security)){
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
die();
}
class connection{
public $value;
public $method;
public $url;
public $type;
function __construct($url,$method,$value,$type=''){
$this->value = $value;
$this->method = $method;
$this->url = $url;
$this->type = $type;
}
function connect(){
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient($this->url);
$result = $client->__SoapCall($this->method, array($this->value));
if($this->type == 'object')
return get_object_vars($result);
$merge = $this->method.'Result';
if($result->$merge->string != '')
return $result->$merge->string;
else
return $result->$merge;
}
function __destruct(){
unset($this->value,$this->url,$this->method,$this->type);
}
}
?>
but when i want use function in top i cant! u make request with android and i'm 100% sure that android part is so fine and good.
the problem is php.
i cant send sms using this code in another php class or php file. but i used it before with same codes!
so whats ur suggestion?
I'm trying to understand recursion :) Well, specifically fetching a full YouTube playlist using Google's PHP Client Library.
This is my function in my class called YTFunctions. It first gets called with a valid, authenticated YouTube_Service object and a playlistId. Then, it should theoretically call itself over and over again as long as the PlaylistItems response has a nextPageToken and then append that to its outputs which should contain all objects (videos) contained in the playlist. For some reason, it just return an empty array.
public static function getFullPlaylistByID($youtube, $playlistId, $pageToken) {
$params = array(
'maxResults' => 50,
'playlistId' => $playlistId,
);
if ($pageToken !== false) {
$params['pageToken'] = $pageToken;
}
$playlistResponse = $youtube->playlistItems->listPlaylistItems('snippet,contentDetails', $params);
error_log(count($playlistResponse['items']));
$playlistItems = $playlistResponse['items'];
if (isset($playlistResponse['nextPageToken'])) {
$playlistItems = array_merge($playlistItems, YTFunctions::getFullPlaylistByID($youtube,$playlistId, $playlistResponse['nextPageToken']));
} else {
}
return $playlistItems;
}
I am clearly missing something here, any help would be greatly appreciated.
Tobias Timpe
here my class that will get all playlistItems
<?php
class yt{
public $DEVELOPER_KEY = '{DEVELOPER_KEY}';
public $client;
public $youtube;
public function __construct(){
$this->client = new Google_Client();
$this->client->setDeveloperKey($this->DEVELOPER_KEY);
$this->youtube = new Google_YoutubeService($this->client);
}
public function getPlaylistItems($playlist, $maxResults, $nextPageToken = ''){
$params = array(
'playlistId' => $playlist,
'maxResults' => $maxResults,
);
// if $nextPageToken exist
if(!empty($nextPageToken)){
//insert $nextPageToken value into $params['pageToken']
$params['pageToken'] = $nextPageToken;
}
$youtubeFeed = $this->youtube->playlistItems->listPlaylistItems('id,snippet,contentDetails', $params);
// function for looping our feed and entry
$this->setFeed($youtubeFeed);
//check if nextPageToken are exist
if(!empty($youtubeFeed['nextPageToken'])){
$insert = $this->getPlaylistItems($playlist, $maxResults, $youtubeFeed['nextPageToken']);
// return to function if nextPageToken are exist
return $insert;
}
}
}
$yt = new yt();
?>
and than use our class
$yt->getPlaylistItems('PL0823049820348','25');
I'm having a very strange and weird issue in Facebook connect API inside my Codeigniter 2.1 project. My site has social login feature and all the codes I test in my localhost works perfectly well. But When I upload my project to the hosting server, Facebook connect library returns null object all the times.
I'm using facebook-php-sdk 3.2 and bellow here is the code I that I'm using.
in the config folder I've a file named, facebook.php that contains
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
$config = array(
'appId' => 'xxxxxxxxxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
);
?>
I've a library named Fbconnect.php under my library folder. Contains code
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
include (APPPATH . 'libraries/facebook/facebook.php');
class Fbconnect extends Facebook {
/**
* Configured the facebook object
*/enter code here
public $user = null;
public $user_id = null;
public $fb = false;
public $fbSession = false;
public $appkey = 0;
public function __construct() {
$ci = & get_instance();
$ci->config->load('facebook', true);
$config = $ci->config->item('facebook');
parent::__construct($config);
$this->user_id = $this->getUser();
$me = null;
if ($this->user_id) {
try {
$me = $this->api('/me');
$this->user = $me;
} catch (FacebookApiException $e) {
error_log($e);
}
}
}
}
?>
and below here is my controller's code
public function fb_login()
{
$this->load->library('fbconnect');
$user_data = array(
'redirect_uri' => actionLink("signup", 'social', 'Facebook'),
'scope' => 'email'
);
redirect($this->fbconnect->getLoginUrl($user_data));
}
I've created a helper function named actionLink, here is it's code
function actionLink($controller = '', $action = '', $param = '')
{
$url = base_url();
if (strlen($controller) > 0) {
$url .= "$controller";
if (strlen($action) > 0) {
$url .= "/$action";
if (strlen($param) > 0) {
$url .= "/$param";
}
}
}
return $url;
}
Please Help.
In Signup.php replace line nos. 37 to 46 with the following: //inside function social($userType = 'Web')
1. Try Solution No.1 Just to make sure that its working but its not genral, It's specific to Facebook.
2. Solution No.2 is same as what you have done but in CI's Way :)
Solution No. 1:
$this->load->library('fbconnect');
$socialId = $this->fbconnect->getSocialId();
$this->data['social_id'] = $socialId;
$email = $this->fbconnect->getEmail();
$this->data['email'] = $email;
$name = $this->fbconnect->getName();
$this->data['name'] = $name;
$this->data['url'] = $userType;
Solution No. 2:
$className = $userType . "SocialService";
$this->load->library($className);
$socialId = $this->$className->getSocialId();
$this->data['social_id'] = $socialId;
$email = $this->$className->getEmail();
$this->data['email'] = $email;
$name = $this->$className->getName();
$this->data['name'] = $name;
$this->data['url'] = $userType;
Actually Your main problem is in FacebookSocialService.php. You are trying to call a private method within a public method in an incorrect way. That's the reason you are not able to fetch any details. Solution for that is as follows:
Inside your public methods
public function getSomeData()
{
$fbSocialService = new FacebookSocialService();
$some_fb_data = $fbSocialService->getFacebook()->user['some_fb_data'];
return $some_fb_data;
}
But rather than doing this, You can just make the private method as public. ;) (Just kidding, but its very quick fix) :P
Let's say I have a class...
class A {
private $action;
private $includes;
public function __construct($action, $file) {
//assign fields
}
public function includeFile()
include_once($this->file);
}
$a = new A('foo.process.php', 'somefile.php');
$a->includeFile();
As you can see, includeFile() calls the include from within the function, therefore once the external file is included, it should technically be inside of the function from my understanding.
After I've done that, let's look at the file included, which is somefile.php, which calls the field like so.
<form action=<?=$this->action;?> method="post" name="someForm">
<!--moar markup here-->
</form>
When I try to do this, I receive an error. Yet, in a CMS like Joomla I see this accomplished all the time. How is this possible?
Update
Here's the error I get.
Fatal error: Using $this when not in object context in /var/www/form/form.process.php on line 8
Update 2
Here's my code:
class EditForm implements ISave{
private $formName;
private $adData;
private $photoData;
private $urlData;
private $includes;
public function __construct(AdData $adData, PhotoData $photoData, UrlData $urlData, $includes) {
$this->formName = 'pageOne';
$this->adData = $adData;
$this->photoData = $photoData;
$this->urlData = $urlData;
$this->includes = $includes;
}
public function saveData() {
$this->adData->saveData();
$this->photoData->saveData();
}
public function includeFiles() {
if (is_array($this->includes)) {
foreach($this->includes as $file) {
include_once($file);
}
} else {
include_once($this->includes);
}
}
public function populateCategories($parent) {
$categories = $this->getCategories($parent);
$this->printCategories($categories);
}
public function populateCountries() {
$countries = $this->getCountries();
$this->printCountries($countries);
}
public function populateSubCategories() {
//TODO
}
private function getCategories($parent) {
$db = patentionConnect();
$query =
"SELECT * FROM `jos_adsmanager_categories`
WHERE `parent` = :parent";
$result = $db->fetchAll(
$query,
array(
new PQO(':parent', $parent)
)
);
return $result;
}
private function getCountries() {
$db = patentionConnect();
$query =
"SELECT `fieldtitle` FROM `jos_adsmanager_field_values`
WHERE fieldid = :id";
$result = $db->fetchAll(
$query,
array(
new PQO(':id', 29)
)
);
return $result;
}
private function printCountries(array $countries) {
foreach($countries as $row) {
?>
<option value=<?=$row['fieldtitle'];?> >
<?=$row['fieldtitle'];?>
</option>
<?php
}
}
private function printCategories(array $categories) {
foreach($categories as $key => $row){
?>
<option value=<?=$row['id'];?>>
<?=$row['name'];?>
</option>
<?php
}
}
}
And the include call (which exists in the same file):
$template = new EditForm(
new AdData(),
new PhotoData(),
new UrlData($Itemid),
array(
'form.php',
'form.process.php'
)
);
$template->includeFiles();
And the main file which is included...
if ($this->formName == "pageOne") {
$this->adData->addData('category', $_POST['category']);
$this->adData->addData('subcategory', $_POST['subcategory']);
} else if ($this->formName == "pageTwo") {
$this->adData->addData('ad_Website', $_POST['ad_Website']);
$this->adData->addData('ad_Patent', $_POST['ad_Patent']);
$this->adData->addData('ad_Address', $_POST['ad_Address']);
$this->adData->addData('email', $_POST['email']);
$this->adData->addData('hide_email', $_POST['hide_email']);
$this->adData->addData('ad_phone', $_POST['ad_phone']);
$this->adData->addData('ad_Protection', $_POST['ad_Protection']);
$this->adData->addData('ad_Number', $_POST['ad_Number']);
$this->adData->addData('ad_Country', $_POST['ad_Country']);
$this->adData->addData('ad_issuedate', $_POST['issuedate'] . '/' . $_POST['issuemonth'] . '/' . $_POST['issueyear']);
} else if ($this->formName == "pageThree") {
$this->adData->addData('name', $_POST['name']);
$this->adData->addData('ad_Background', $_POST['ad_Background']);
$this->adData->addData('ad_opeartion', $_POST['ad_operation']);
$this->adData->addData('ad_advlimit', $_POST['ad_advlimit']);
$this->adData->addData('ad_status', $_POST['ad_status']);
$this->adData->addData('ad_addinfo', $_POST['ad_addinfo']);
$this->adData->addData('ad_description', $_POST['ad_description']);
$this->adData->addData('tags', $_POST['tags']);
$this->adData->addData('videolink', $_POST['videolink']);
} else if ($this->formName == "pageFour") {
foreach($_POST['jos_photos'] as $photo) {
$this->photoData->addData(
array(
'title' => $photo['title'],
'url' => $photo['url'],
'ad_id' => $this->photoData->__get('ad_id'),
'userid' => $this->photoData->__get('userid')
)
);
}
}
Update
Strange: while the error itself hadn't been quite related to what the problem was, I found that it was simply an undefined field which I hadn't implemented.
Consider this thread solved. To those who replied, I certainly appreciate it regardless.
This should work. Are you sure you're doing the include from a non-static method that's part of the class (class A in your example)? Can you post the exact code you're using?
Edit: As general advice for problems like this, see if you can trim down the code so the problem is reproducible in a short, simple example that anyone could easily copy/paste to reproduce the exact error. The majority of the time, you'll figure out the answer yourself in the process of trying to simplify. And if you don't, it will make it much easier for others to help you debug.