PHP - Restful Service Using Tonic Framework
I am trying to create a web service using restful service tonic frame work to pull data from my website www.serviidb.com and I can print_r the output to firefox poster. I am using SQL queries to pull the data form a mysql database. I would like to be able to select the query for the data I want at the beginning of the code and select the output format at the end. I am looking at having sections of the code to get "plugins", "video", "audio", and "user". I am thinking about use select case to determine the mysql query to run. I have programming exp in VB, basic and fortran.
Here is the URL I am using for the get command. Code: [Select] http://serviidb.com/api/plugins here is the code I am using right now. Code: [Select] <?php class TaskDataManager { public static function get($taskId, $input){ echo $taskid . "\n"; //Connect To Database $hostname='hostname'; $username='username'; $password='password'; $dbname='dbname'; mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.'); mysql_select_db($dbname); //echo 'taskid: ' . $taskId . "\n"; if($taskId=="plugins"){ //echo $input . "\n"; $plgnsql='SELECT taxonomy_term_data.name, field_revision_field_revision.field_revision_value as version, file_managed.uri as URL' . ' FROM taxonomy_term_data ' . ' left join field_data_field_plugins on taxonomy_term_data.tid = field_data_field_plugins.field_plugins_tid ' . ' left join field_revision_field_revision on field_revision_field_revision.revision_id = field_data_field_plugins.revision_id ' . ' left join file_usage on field_data_field_plugins.entity_id = file_usage.id' . ' left join file_managed on file_usage.fid = file_managed.fid' . ' WHERE (field_data_field_plugins.bundle ="plugin")' . ' '; //$format='json' $result = mysql_query($plgnsql); //$mark =jsob_encode("plugins"); $plugins = array(); //echo $result . "\n"; //$response->addHeader('Content-type', 'application/json'); while($response = mysql_fetch_array($result, MYSQL_ASSOC)){ $response[URL] = substr_replace($response[URL],'http://serviidb.com/sites/default/files/',0,9); $reponse = json_encode($response); print_r ($reponse) . "\n"; } //print_r ($response) . "\n"; return true; } if($taskId=="video"){ echo $input . "\n"; //echo "started feed code" . "\n"; return true; } } } ?> Here is the output I am getting. I am trying to figure out how to get the json output to look like the second code below. Code: [Select] {"name":"Blip TV","version":"0","URL":"http:\/\/serviidb.com\/sites\/default\/files\/createplugin\/BlipTVUrlExtractor.groovy"}{"name":"CBS","version":"0","URL":"http:\/\/serviidb.com\/sites\/default\/files\/createplugin\/CBS.groovy"}{"name":"iPlayer (UK)","version":"1","URL":"http:\/\/serviidb.com\/sites\/default\/files\/createplugin\/IPlayer.groovy"}{"name":"4oD (UK)","version":"1","URL":"http:\/\/serviidb.com\/sites\/default\/files\/createplugin\/Channel4od.groovy"}{"name":"YouTube","version":"1","URL":"http:\/\/serviidb.com\/sites\/default\/files\/createplugin\/youtube.groovy"}{"name":"LiveFeeds","version":"3","URL":"http:\/\/serviidb.com\/sites\/default\/files\/createplugin\/livefeeds.groovy"}{"name":"GameSpot","version":"1","URL":"http:\/\/serviidb.com\/sites\/default\/files\/createplugin\/gamespot.groovy"} Want. Code: [Select] {"plugins":[{"name":"Blip TV", "version":0, "url":"http:\\serviidb.com/sites/default/files/Create Plugin/BlipTVUrlExtractor.groovy"},{"name":"CBS", ....}]} I am also trying to figure out how to get the output in the xml format also. Thanks is advance for the help. Similar TutorialsOkay, On my original problem, I have been able to authenticate with the web service login service, and extract a cookie as follows from the web-service: $s_Cookie = $agLoginService->agGetCookie(); $s_Cookie = AGSESSION=oxhbjcKtPw5sOymAD8m8KcKR6JL4i+TIE5mZxwOrXLwCRr8iTOvPxA==; Now, I create data access soapclient: $agDataService = new SoapClient($s_DataURL, $a_SoapOptions); //yes I know I should build my own class wrapper around soapClient, but I am trying to make sure I know what to build before I do next in the process I need to set the cookie for the data access service. I tried using: <b>$agDataService->__setCookie('cookie', $s_Cookie);</b> but I don't think it's right because when I call any of the service's functions, I get no data back. This is what their engineer had to say ( he is no help in php at all) This is a question referring the http headers. He needs to set the cookies as given in the examples on the wiki page. The cookie is specified in a response http header as: Set-Cookie. So the http headers he got back are correct. The cookie he has to set is AGSESSION=oxhbjcKtPw5sOymAD8m8KcKR6JL4i+TIE5mZxwOrXLwCRr8iTOvPxA==; There should be an api for setting the cookie if not there is one for setting the http header. Set the http header name for the request (cookie - notice that is different than what you get back from an http response - read the rfc spec for http for all of the details) then set the value. The semi colon at the end is the delimiter for http headers (in the rfc). That is all he needs to do if he gets back some login error that means the cookies did not get set correctly. Any ideas or help will be great. Thank you. This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=347122.0 I'm getting the following result from a web service call. I'd like to pass it to another page, possibly using sessions, and then access specific values on that page, such as FirstName.
stdClass Object ( [GetProspectAsJSONResult] => [ { "ProspectId": xxxxxx, "Keycode": "Test", "FirstName": "Test", "LastName": "Test", "Company": "Test","Email": null } ] )
I'm not sure what the best way to do this is.
Thanks!
Hi Guys/Gals, I am new to PHP and when I say new, I mean I know a variable is $variable name... that is about it. I am a .Net developer, always was, now I have to learn some php. I have a .Net payment gateway service that I would like to reference from a php site. I was hoping anyone could point me in the right direction on how to go about adding a .Net Service and pointing to it in PHP. Please note this is a WPF service, thus it is a .svc page not a .asmx and it is hosted and running on iis on a server. Please some guidance? Any help would be appreciated. Hi, guys. I just developed and published first version of 12framework for iOS which can call also PHP web services.
It is web service client which generates dynamic forms from web service results, and enables insert, update and delete of records. You can simply change result field type to text, memo, date, bool.
I also made some simple PHP web service to test functionallity of application, so I will really appreciate your feedback. iOS is locked platform, so 12framework provides possibility, to make some useful data forms that works as native application. Link: https://itunes.apple...88083?ls=1&mt=8
I wirte php... do i use a framework?.. if so what framework do i use?... When i do phpinfo(); ... i get a screen that says: This program makes use of the Zend Scripting Language Engine: so do i use the zend framework? regards J Hi, I have been doing small scale programming but I am now planning to foray into large scale, intensive web application to handle high traffic, definitely I need something fast, efficient and re-usable. Since I am programming for a while, I have my own collection of code which I use for base and generally am able to build fast and secure (small) web application. But now I am looking into framework. So, here is the question.. Should I look into framework like Yii , Kohana etc.. or Should continue building on my own code .. I just don't want to learn all those framework if and but then at the decides not to use them as I find them not really helpful !!! Hi, I'm trying to write my own php mvc framework, but I don't know where to start. I have been using codeigniter for a while, then i thought i shouldn't use it, because I'm not getting smarter when most of the code is written for me. So, writting my own framework would be a great practice to learn oop, i guess. I need: url routing, the would work like codeigniter's (http://website.com/controller/method/some/other/params) and calling some function for rendering layout files similar to codeigniter's ($this -> load -> view ( 'file.php' ); and not like this: $header = new Template ( 'header.php' ); then some coding with header, and same with content.php and footer.php). Can anyone please help me? Where to start? sorry for bad English I have service /usr/lib/systemd/system/socketserver.service defined as follows: [Unit] Description=Socket Server After=syslog.target [Service] ExecStart=/usr/bin/php /var/www/socket/server.php Restart=on-abort Restart=on-failure RestartSec=10s [Install] WantedBy=multi-user.target When hitting the following lines: $cmd="tshark -f 'port 1337' -i eno16780032 -a duration:4 -w /var/www/socket/tmp/test.pcap"; $status = exec($cmd, $output); syslog(LOG_INFO, 'results: '.json_encode($output).' status: '.($status?'success':'false')); I get the following: Jun 04 18:58:56 tapmeister.com php[43111]: Running as user "root" and group "root". This could be dangerous. Jun 04 18:58:56 tapmeister.com php[43111]: Capturing on 'eno16780032' Jun 04 18:58:56 tapmeister.com kernel: device eno16780032 entered promiscuous mode Jun 04 18:59:00 tapmeister.com kernel: device eno16780032 left promiscuous mode Jun 04 18:59:00 tapmeister.com php[43111]: 0 packets captured Jun 04 18:59:00 tapmeister.com Server[43111]: results: [] status: false Sure enough, exec('whoami') confirms I am running as root. Probably shouldn't be. How would you recommend configuring? PS. the three lines shown regarding tshark are executed via an asynchronous request and are not in the main loop. HI, I need to know how to get the response objects from a webserve call. I call the following webservice: $params = array('mobiUser'=>"WJBASSON",'mobiPass'=>"83dop"); $soap = new SoapClient('http://172.18.22.182/csp/ampath/ReportGeneration.Mobi.Services.cls?WSDL'); $result = $soap->login($params); When I do var_dump($result) I receive the following: stdClass Object ( [loginResult] => stdClass Object ( [MobiRegUserID] => 34 [MobiRegUserName] => WJBasson ) ) I need to know how can I get the values of objects MobiRegUserID and MobiRegUserName ?? Hi, I'm new to PHP and wondered if anyone could help... I am consuming an asmx webservice using PHP code. (Later to make a widget for wordpress). I can receive all the data, but it is in one very big xml file. I want to be able to convert this data, so I can make it more readable. Could really do with help as I don't have a clue how to convert it. ANy ideas? Hi! I need to retrieve data from a WCF Web Service and don't seem to be connecting when the "new SoapClient" is called. I am using php version 5.2. The service requires 2 Parmameters, an account ID and a comma separated email list. Can someone please tell me what I am doing wrong? Thanks! Code: [Select] <?php header('Content-Type: text/xml'); $client = new SoapClient('http://www.zbestlistings.com/WCF/Primedia.svc?wsdl'); $response = $client->GetPropertyXML(array( "AccountID" => "12807175152", "eMailList" => "Sheryl@Rentingslc.com, Tenants@Rpmwestvalley.com, Tom@Rpmsouthernutah.com" )); echo $response; ?> Curious how to set a returned value from a web service to a php variable? Code: [Select] $tid= $_POST['tid']; $client = new SoapClient("http://www.sitename.com/WebSvc.asmx?WSDL"); $result = $client->getName(array('tid'=>$tid)); echo json_encode($result); Returns this: Code: [Select] {"getNameResult":{"count":1,"results":{"TaggedText":{"tid":"001","text":"John Smith"}}}} How do I set a php variable $RetName to equal John Smith? I tried Code: [Select] $RetName = $text; But that didn't work. Any help is apprecaited. Thanks, sanchez Hello
I am looking for a way to log all incoming requests to a nusoap web service to a file.. any suggestions?
Thanks
Hi everyone. I am looking at creating my application's back end with PHP, which returns all data with Jason or simplexml. I have tried Slim once, but think there should be something easier to use. Can anyone give me suggestions on what I can use which is easy to catch on, and maybe an example? Appreciate it. Kind regards I know this question sounds a bit vague. I have not been working with php too long, maybe 6 months or so. I have worked with other programming languages and do have a good grasp of OOP. I have a few ideas for some apps I want to make, nothing that will be the next commercial hit. I just to do some php apps to get better at php. Everywhere I look some one is talking about a framework, and it looks like Codeigniter seems to be everyones fave, despite the fact that there is a good chance it will die out soon. I ended up giving Codeigniter a try and although I understand MVC, and I get OOP, and all of that, it seems there are many ways to set things up and a lot of the tutorials I tried out had different ways to do things withing Codeigniter, the problem with that is some of the stuff I learned on tutorials I could not get to work on my set up. I got frustrated and simply gave up after a while of tinkering with CI. I know there are plenty other frameworks, but I am wondering if I will truly be at a disadvantage if I just write core php with out using a framework.
Thanks if advance for the input.
hey guys im having a bit of trouble getting $_GET in my framework. now the ony way to get query from a url such as:
users/activate-account?email_address=test&token=test
i have to use $_SERVER['REQUEST_URI'] unless im doing something wrong?
[REQUEST_URI] => /bisi/user/activate-account?email_address=test&token=test
by doing this:
print_r($_GET);all i get is : Array ( [uri] => user/activate-account ) just concerned im doing something wrong?...any advise on this please guys. was thinking of doing something like this in my request public function get_query($name = null) { $uri = $_SERVER['REQUEST_URI']; if (parse_url($uri, PHP_URL_QUERY)) { $query = explode("?", $uri); $query = explode("&", $query[1]); $array = array(); foreach ($query as $string) { $string = explode("=", $string); $query_name = $string[0]; $query_value = $string[1]; $array[$query_name] = $query_value; // $_GET[$query_name] = $query_value; possibly? } if ($name !== null && array_key_exists($name, $array)) { return $array[$name]; } return $array; } return null; }thanks Okay, this is a head scratcher for me... About 10-15 years ago, there was this framework that seemed to be pretty popular in the LAMP work for quickly building websites. (I think it was written in PHP.) The thing I recall about it was that it you could create your own markup tags to markup up fields using curly brackets { }. I wish I could be more specific but this is all that is coming to mind. Any clues of what I might be thinking about? hey guys im after a bit of advise on routing within my framework please.
now i've created a route:
account/verify/email-address/:email_address/activation-key/:activation_key
which will be then interpurated into
account/verify/email-address/destramic-at-hotmail-dot-com/activation-key/12345
now my question is having a email address in a url is good idea?
if so i can decode the :email_addres parameter in the route like so:
$router->add_route('account/verify/email-address/:email_address/activation-key/:activation_key', array('controller' => 'users', 'action' => 'activate_account', 'decode' => 'email_addres' => 'string_to_email') ));would like your thoughts on this please guys (go easy)...if not a user_id would be sufficient i suppose thanks |