Slim PHP Framework Help - php

I just added the Slim framework to my website in order to create a rest API. But I currently have a problem. I wrote this code as a test to check to see if a get request would work, but whenever I try calling the url, http://mysite.com/api/rest/hello/max, I get a website not found error. Please can you tell me what is going wrong?
Slim::init();
Slim::get('/hello/:name', 'hello');
function hello($name) {
echo "Hello, $name!";
}
Slim::run();

You have propably forgotten to put the .htaccess file provided with Slim in the same directory as your index.php.

Related

CakePhp Getting Entity 'raquo' not defined error when calling SOAP wdsl file

Im trying to connect to the FedEx PHP plugin, Ive successfully ran the plugin with my local Server. But when I try to run it on my CakePhp project I get the next error:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://my-subdomain.mydomain.com/controller/wsdl' : Entity 'raquo' not defined
Using the url I can actually enter the wdsl page and see the file in XML file. I got a function and view which return this. This is that functions code:
public function wsdl() {
$this->layout = false;
$this->RequestHandler->respondAs('xml');
}
I can enter the url and see the correct display of the XML. Then when I try using the wsdl on my function which is in the same class I get the error above. This is the code I use to call the SOAP class:
//The WSDL is not included with the sample code.
//Please include and reference in $path_to_wsdl variable.
$path_to_wsdl = "http://apibebe2go.bebe2go.com/home/wsdl";
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient($path_to_wsdl, array('trace' => 1));
I get and internal error from the CakePhp debug and the error above. Any ideas what I could try to make this work? If you guys need any more code Ill be happy to help :D
Ok I solved the problem another way. Not sure why the /wdsl file was not working when called via function to view, BUT I added the .wdsl file to the WebRoot file path I had and called the url from there. Now it works like it should. If you need further explanation on how I achieved this, feel free to ask here :D
Cheers! :P

Facebook php SDK - simple datafetch

I'm trying to integrate my facebook app with PHP. What I need to do is have users go to the app-page, authenticate the app and then somehow I want to end up with a variable that contains the info I need so I can store it in MySQL.
I downloaded the facebook SDK, but I cannot figure out how to make it work. All the examples I can find refer to a file called facebook.php - but there is no such file in the SDK (maybe the changed it?).
I managed to get it working with JavaScript, but I don't know how to get from JavaScript to php (the user object, that is).
I would prefer to just run it entirely through php. What I'm trying to do is very simple, but I don't understand what I'm doing wrong. The following, for instance, does not work:
<?php
FacebookSession::setDefaultApplication('appid', 'appsecret');
require facebook-php-sdk-v4-master\src\Facebook\FacebookCanvasLoginHelper.php;
$helper = new FacebookCanvasLoginHelper();
try {
$session = $helper->getSession();
} catch(FacebookRequestException $ex) {
echo "error";
} catch(\Exception $ex) {
echo "error 2";
}
if ($session) {
echo "logged in";
}
?>
Gives PHP Fatal error: Class 'FacebookSession' not found in
Where do I go? I don't think the Facebook getting started guide is helpful at all. It just starts out with "you have to do this" (what I did above) - but that doesn't work?
Looks like they changed the whole SDK for PHP 5.4.
Well there's a few options, you could go with the older SDK and all those tutorials you found will work for that. Or you could learn some new things!
I suggest that if you want to use the new Facebook SDK, you go ahead an learn about composer first, it makes including libraries a piece of cake and all you'd have to do is include the autoloader at the top of the file. Once done, you can just follow the example and it should work.
If you don't want to learn composer, you'll have to include all the required files manually. Here's a basic example.
In your example it looks like the error was because you were calling
FacebookSession::setDefaultApplication
Before you'd actually included the SDK

500 Internal server error with new php files on server (Wordpress/Woocommerce)

I am getting a strange 500 Internal Server Error with a new script I am trying to implement in the actual site. Here's a screen:
![500 Internal][1]
I can route to this files manually without problems and they are working too. But not in the script itself. The Paths are also correct.
Heres the link to the Site:
[>>> Link <<<][2] (just enter R10369 in the input field or a random number)
Everything else is working correctly except these 3 files:
reseller.php,
checkresellerid.php,
resellermail.php
I googled a bit and everywhere is the .htaccess mentioned. but I never modified it or overwrited it. What could be the Problem? Thanks for any Help and sorry for my bad Englisch.
(Let me know if you want to see the php files)
EDIT: I managed to include my new php files into wordpress but i still got the 500 Error
I checked out the website.
I think Wordpress doesn't let you call .php inside of it's system.
I mean you cannot call PHP files for ajax.
You need to use wordpress ajax. Here is a snippet how to use ajax:
Function.php in your theme file.
function myajax()
{
//do stuff
die();
}
add_action( 'wp_ajax_nopriv_product_s', 'myajax' );
add_action( 'wp_ajax_product_s', 'myajax' );
And in your javascript file using jQuery:
The url may change, maybe it's enough to have wp-admin/admin.ajax.php or something like this, i don't really remember right now.
$.post('/wp-admin/admin-ajax.php',{action:'myajax',yourdata:"mydata"}).done(function(data)
{
//do stuffs
});
Update:
So basically if you want to have ajax request inside wordpresss, you need to define these things and use it like this. the "action" parameter is the function name which you want to call. And you need to put the PHP code into your current theme's function.php.

Path in an AJAX call keeps changing in ZF2

I have a bit of an annoying problem in Zend Framework 2. My js, which is located in my public/js folder, calls an action in the controller for my admin module. This is the call:
$.post('admin/expand', {
id: CCID
},function(data){
if(data.hasOwnProperty('info')){
expand(data.info);
} else {
console.log('Can\'t find customer info.');
}
},'json');
The call works fine normally, but then sometimes it won't be able to find the action. The console will say:
POST http://localhost/admin/admin/expand 404 (Not Found)
So I'll change the path in the AJAX to just 'expand' instead of 'admin/expand' and it'll work for a while... and then it won't until I change it back!
So it seems that sometimes it gets confused about the routing and sometimes it doesn't. Is this a namespace problem? The js file is supposed to be in my root/public/js, right? Does anyone know what the problem is here?
Try changing the url from admin/expand to /admin/expand . It is more pragmatic to use ZF2 routes.

CodeIgniter RESTful API Library Response

This question is related to the CodeIGniter RESTful API library found here. I hope someone here is using this library and can offer some help :) .
http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/
I have installed this library and set up a working environment with it. I have been able to get data back as well. For use, I have created a very simple class that I am accessing with the following code:
<?php
require APPPATH.'/libraries/REST_Controller.php';
class Users extends REST_Controller
{
public function list_get()
{
$this->load->database();
$data = $this->db->get('users')->result();
$this->response($data, 200);
}
}
To get at this controller, I have done a call to the following URL:
"http://localhost/mgtapp/index.php/api/users/list/format/json"
While I am getting back data, I see that the header content type is set to text/html instead of json and I am also getting errors in php that say "headers already sent". I have tried to remove the format from the end of the url and send it in via an "accept" but I get the same errors and I see the content type being set as text/html. When I run the example, I see the response coming back as it should (as json in the content type) so I do not understand what I am doing wrong here that the content type is not being set correctly. IF someone can shed some light it would be super helpful!
Thanks!
So I am answering this question because the reason for my troubles was a stupid one.
I had a couple of lines under the "?>" of my php class controller and apparently that was messing it up. Sorry!
Anybody else with this issue, check that first!

Categories