I am new to code with NuSOAP lib. Currently, I've just accomplished connected client with server and get service.
Right now, my service or function is on the same php file as soap server. I register my function that on the same page using this code :
$server->register("myFunction");
how can I register a function if I have external php file that consist my function that I needed ?
first, you need to include your php file in your code, and before, register the method or function.
Be sure if your function need to parameters or has a return. In that case, you must inscribe your parametes and return statements using the method register of the webservice.
See here http://www.wackylabs.net/2004/07/creating-a-web-service-and-wsdl-using-nusoap/
In that example, when you see > replace by >
Related
Hi i'm pretty new on create endpoints in php.
Now i have to create a little endpoint to intercept some updates from electronic invoice service.
From admin panel of the service i can specify endpoint url where my application is located.
For example I indicate: www.example.com/api/endpoint/index.php
NOte: If I set only www.example.com/api/endpoint/, panel admin tell me there is an error - page not found
Now in the admin panel I see I can intercept these POST methods:
/createInvoice
/createNotification
But i don't undertand HOW to differentiate there 2 methods...
Actually in my index.php i've:
<?php
function call_create_invoice(
...
);
function call_create_notification(
...
);
header('Content-Type: application/json; charset=utf-8');
var_dump($_POST);
If I use POSTMAN to do some test using POST call, i can correctly see $_POST parameters sent.... but i don't understand how to:
call call_create_invoice function if /createInvoice is called
call call_create_notification function if /createNotification is called
If you would stick to vanilla PHP, you need to parse the request URI to call the desired function like:
$path = $SERVER['REQUEST_URI'];
switch($path) {
case('/createInvoice'):
call_create_invoice();
break;
case('/createNotification'):
call_create_notification();
break;
}
As requirements grow, it may make sense to use a minimal PHP framework with routing functionality, such as Laravel Lumen.
Hi I am facing some problems in writing a cron job using CI CLI way. My application has a controller name called manager.php in that there is method called check_status where I am gonna get all the order_ids using one model function. Ever order_id row had a status filed in database which either success or failure.
I have an api if i pass order_id to that it will tell whether order is successfully delivered or not. But here comes the problem I have below line in controller in the top.
<?php if(! defined('BASEPATH') ) exit("NO Direct Script Access Allowed"); ?>
So when i try to run method check_status from CLI in CI it gives me an error stating NO Direct Script Access Allowed.
This is the way i called above method php application/controllers/manager.php check_status
So i decided like this i created an another class file called cron_job.php in that i didn't keep the above error line "No Direct Script Access Allowed". I thought it will give access now when i try to run but it doesn't give an error and even output also.
This is the class which i created and method in that.
<?php
class Cron_job extends CI_Controller {
public function message($to = 'World')
{
echo "Hello {$to}!".PHP_EOL;
}
}
?>
I run this controller form CLI like this php application/controller/cron_job.php message
Note: I am in ROOT directory.
No Output at all. So i tried in another way like this php index.php application/controller/cron_job.php message
Now it gives me error stating that Error 404 page not found.
What i tried in another way now i created a file in views folder and in that i am calling old controller/method url like below.
$result = file_get_contents("http://application_path/controller/method");
echo $result;
Now i am getting output which i defined in the method check_status in manager.php controller.
But here comes another problem now after the above line i will get an array output which had all the order_ids.
I am gonna send this each id to a api to check status. If it is failure it will check whether it is delivered or not. If it's done i need to update that status in the database against that order_id. But now i am in view file, is it possible to call a model file from the view file or is there any way to do this.
Any help?
Note: There is no syntax errors in any controller or any method , which are fully verified and working normally when i am accessing using urls.
You need to read the CodeIgniter help section on Running via the Command Line. It's very easy. Your original approach was correct. But you do not call your controller method directly by its path, instead CD to your project root and then the call the index.php file with the controller and method as parameters.
// This is how you call CI via the command line.
// Use spaces between index.php and your arguments.
$ php index.php <controller> <method> [params]
// And in your instance
$ php index.php manager check_status [param1 param2 param3]
Depending on your host you may need to call the PHP version compiled for CLI.
the ci helper will help you in this.
1 ) Create a helper & create a function in it, that calls your model function
function getUserDetails($userId = '') {
$CI = & get_instance();
$getUserDetailsByUserId = $CI->user_model->getUserDetailsByUserId($userId);
return $getUserDetailsByUserId;
}
2) Now you can call getUserDetails($userId); in your view.
Here's the situation:
I have a catch-all on my domain email (so *#domain.com) redirecting to a piping script located at /home/domain/scripts/piper.php. This piper script is not within the Kohana ORM, but all of my other files are. I want to try to use Kohana inside this piper.php file.
I have tried (unsuccessfully) all of the following:
Including Kohana
I couldn't figure out what needed to be included, and more importantly how to override the url variable that Kohana uses to determine the right controller. Also, this is a catch-all piper, so it isn't using HTTP (to my knowledge), so much as executing a command.
Piping
I tried piping to the following:
/home/domain/public_html/index.php --uri="piper"
But cPanel makes this impossible, as you can only specify the destination script, and not the proper flags and such (unless I am missing something).
PHP exec()
I tried using the following line:
exec("php /home/domain/public_html/index.php --uri=\"/piper\"")
I was hoping that the stdin data would be maintained across the exec() command, but I could never get it to recognize the uri command, though I can run this on my localhost and it works just fine.
I was using http://www.coderelic.com/2011/10/creating-cron-jobs-in-kohana-3-x-is-a-piece-of-cake/ as a reference, but can't get anything to work.
I'm happy with either one of these solutions such that I can see an incoming email, parse it, then send emails based on the parameters.
Let me know if you need more information! I'm le stumped.
/home/domain/public_html/index.php --uri="piper" would be a valid way to do it. If your host sucks and doesn't let you specify that, put it into a bash script instead and reference that.
If you are on any recent version of kohana (3.2 or 3.3), a better way to do this would be to use Minion to run the command line task. This is what Minion was designed for.
All you need to do is to:
modify your piper.php script to be a valid PHP class;
place it in /application/classes/ folder;
Kohana will automatically load your class file (like include) during initialization.
Then you can use your piper class as usual class by $piper = new Piper; ....
UPD
You have to serve your emails trough Kohana.
Create controller, for example pipe (route it with /pipe URL):
public function action_pipe() {
$pipe = new Pipe; // This creates new Pipe object (your emails serving class)
$pipe->serve(); // Sserve emails within `serve()` method of Pipe class
}
Although admittedly, I'm not sure if these other answers are correct because I can't figure out how to reproduce the results.
What ended up working for my situation was to create a Controller_Piper class that is called in the /home/domain/scripts/piper.php. What I did was to copy the code from /home/domain/public_html/index.php and changed the following:
echo Request::factory("/piper")
->execute()
->send_headers(TRUE)
->body();
This loads the piper controller and executes everything very nicely. Not sure if it's the cleanest, but it does work.
I'm writing a SOAP API in PHP and I've run into a small problem. The API uses a functions file which contains a function called "GetChallenges()". I'd like my API to have a method with the same name, but since I'm including the functions file, it causes an error saying that I can't redefine that function. I'd really rather not rename the function in the functions file since i'd have to go all through my existing code and change the references. Is there a way to have the name of the function in PHP be something like"GetChallengesApi()" and yet have SOAP be able to run it as just GetChallenges()?
I'm working on converting my standard PHP project to OOP but I ran into a wall about how to handle AJAX calls with PHP Classes. I'm not happy with the way I'm doing this now. I have a TillAjax.php file which I call from my TillUI.php file from a AJAX call.
In the TillAjax.php file I do this to get the information passed from the ajax call.
$till = new Till();
if(isset($_POST['data']))
$till->doStuff($_POST['data']);
I think this ruins the OOP.
I have worked with ASP.NET MVC and here its possible to call a specific action in a controller without i have to check for the post value. So I want to know if there is a smarter PHP way to solve the above problem?
The method I use for this is to have an Ajax class.
Your php file calls Ajax::Process($_GET['handle']), where 'handle' contains the name of a static class method, so perhaps 'Till::Process'. The Ajax class checks the function against a list of permitted functions (i.e. functions that you are allowing to be called via ajax), and then uses call_user_func_array to call the function (my code uses the contents of $_POST as arguments to pass to the function). The return of that function is automatically encoded as json and outputted to the client.
This means that your target php file looks like this:
<?php
//File: ajax.php
include ("Ajax.php");
Ajax::Process($_GET['handle']);
?>
Which I think is pretty simple.
Then you can have javascript that looks like this (jquery) :
$.get('ajax.php?handle=Till::Process', {}, function(result) {
//called on page response
});
So then result now contains whatever data is returned from the php method Till::Process.
Have you considered using a PHP MVC framework such as CodeIgniter, CakePHP, Kohana, etc? They will let you route requests to specific controller methods. It will be a much cleaner solution if migrating to one of these frameworks is an option for you.