I am trying to use the Parse.com SDK with PHP. I have downloaded and installed the SDK and I have successfully created a test object.
However, when trying to retrieve an object with a basic query using the sample code provided in the Parse docs and when I try to run it I get:
Fatal Error: Class 'ParseQuery' not found in /home/jameshilton/public_html/index.php on line 109
I would have guessed that it is not linking to the SDK properly but everything else is working fine.
Any ideas what I'm doing wrong?
By looking at the code of the class ParseClient in on GitHub I can see that the classes are declared in the namespace parse. So when you need an object from the Parse library you need to select the namespace. This can be done in two ways.
At the top of your file write:
use \parse;
or when instantiating the class:
$query = new \parse\ParseQuery
And remember to make sure the files are included either through an autoloader (composer?) or manually using include or require.
Regards.
Related
I want to run custom php code in laravel directly without using any routes or http requests..
I hope I can make it clear, I mean, like those online tools that runs php code by writing php code in browser, and then run it, and view result..
I found this handy project (Run-PHP-Code) to run PHP in browser directly, but I can't use models of my laravel project in PHP code..
How can I include laravel 's environment, so that I can for example:
$tag= new Tag;
where Tag is a model in laravel project, that would result into:
Fatal error: Class 'Tag' not found in D:\xampp\htdocs\widgetsRepository\app\controllers\Run-PHP-Code-master\index.php(49) : eval()'d code on line 3
Any idea? this would be very useful!
EDIT
I tried Brian suggestion at his answer, but I got this error now:
Call to a member function connection() on null
at vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php
public static function resolveConnection($connection = null)
{
return static::$resolver->connection($connection);
}
so, I think I only need to get database sorted, then I can do experiments easily..
I've never tried to run code from a laravel project directly, I just copy and paste parts of the code into Run PHP Code.
That being said, it should be possible to run the code using the method taken from this StackOverflow question:
The Composer autoload script, to autoload all of your classes:
require __DIR__.'/../bootstrap/autoload.php';
And if you need things from the IoC container, you'll:
$app = require_once __DIR__.'/../bootstrap/start.php';
Then you will be able to do things like:
$post = Post::find(1);
I have used composer to download the Angell EYE PayPal library into my vendor directory. Now I'm trying to call the class within a controller.
I've tried various methods:
Use \angelleye\PayPal;
at the top of page. I've tried using the require() method.
Within the controller I have used
$paypal = PayPal::PayPal($payment);
And a few other ways, but I just get the error Class not found at line 179 and I'm not sure why.
You just need to load a config file (depending on your framework) and the autoloader.
require_once('includes/config.php');
require_once('vendor/angelleye/paypal-php-library/autoload.php');
Of course, adjust the paths to suit where you have those saved, but the autoloader is what makes the classes available to you.
If you want more direct help you can submit a ticket here.
Thanks for response.
I actually managed to get it working on the framework.
I did nt have to load anything or require the class as the composer autoload must do it for me in the framework.
I simply added :
$PayPal = new \angelleye\PayPal\PayPal($PayPalConfig);
and it started to work.
Im guessing if i want to use the PayFlow i would call using:
$PayPal = new \angelleye\PayPal\PayFlow($PayPalConfig);
I will definately post back if the rest of the proccess fails to work.
guys, I am trying to use this new Facebook SDK for PHP to allow users to use their profiles on Facebook to login on my website
My website is using CodeIgniter, the PHP framework, but I couldn't make the FacebookSession class to load.
Am following this http://metah.ch/blog/2014/05/facebook-sdk-4-0-0-for-php-a-working-sample-to-get-started/ and this https://developers.facebook.com/docs/php/gettingstarted/4.0.0 tutorials
It keeps saying Fatal error: Class 'FacebookSession' not found and then I tried to move this code out of Code Igniter and yet I can't make it work
I started trying to use 'require_once' to import the class, but it also fails! This is all I have in one simple php file (2 lines):
require_once('src/Facebook/FacebookSession.php');
FacebookSession::setDefaultApplication('YOUR_APP_ID', 'YOUR_APP_SECRET');
It finds the file, presumably imports it (I put some 'echo' inside it and it prints the messages) but fails on the second line
I tried with the autoload.php that comes with the SDK, but it returns in the middle of the script in this condition:
// does the class use the namespace prefix?
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
// no, move to the next registered autoloader
return;
}
Why can't I import this file? It probably has something to do with namespaces, alias etc, right? So can you help me?
Your tutorial includes lines like this:
use Facebook\FacebookSession;
This allows you to use FacebookSession::something() instead of having to write out the full namespaced function Facebook\FacebookSession::something().
Add the use lines and things'll work.
Instead of this
FacebookSession::setDefaultApplication('YOUR_APP_ID', 'YOUR_APP_SECRET');
try this
Facebook\FacebookSession::setDefaultApplication('YOUR_APP_ID', 'YOUR_APP_SECRET');
if it works then use "Facebook\" as prefix with every Facebook class.
I am using the google api php client.
Howewer, when I'm trying to include the three following libraries:
require_once app_path().'/library/googleapi/contrib/Google_PlusService.php';
require_once app_path().'/library/googleapi/contrib/Google_TasksService.php';
require_once app_path().'/library/googleapi/contrib/Google_CalendarService.php';
I get : Cannot redeclare class Google_Acl on line 784 of Google_CalendarService.php.
I know I could modify Google_CalendarService.php so that the class is only created if it doesn't exist, but this is kind of messy.
I need to load both libraries at the same time to create a valid AuthURL to authorize requests on google plus (to get the profile image) and the calendar (to get the calendar).
What's the best workaround for this ?
Seems that it is not possible to use these 3 libraries together
Reply from google code.google-api-php-client
Unfortunately its not the same object - there is name collision in
this version of the library. The alpha version 1.0.0 includes better
name generation that avoids this:
http://github.com/google/google-api-php-client/
The workaround at the moment is not to include both at the same time
unfortunately.
https://code.google.com/p/google-api-php-client/issues/detail?id=439
I am trying to use Searchable Behaviour hosted here: http://code.google.com/p/searchable-behaviour-for-cakephp/
To initialize the search_index table with existing data, I have used this: http://code.google.com/p/searchable-behaviour-for-cakephp/issues/detail?id=1&q=controller Reply No. 2 which creates the class SearchController.
The code was working fine on my local test server which runs PHP5.
However, the server has PHP 4 and when I tried the code on server it gives this error:
Fatal error: Cannot redeclare class searchcontroller in LONG_PATH/cake/app/models/behaviors/searchable.php on line 2
Does it really has to do something with the PHP version or have I done some logical mistake?
Not sure, but you could try my Searchable plugin instead
I just changed the name of the search Initialization controller and it worked. Looks like there is a Search Class created with Searchable behaviour.
Also, while using searchable plugin for CakePHP 4.x.x, if html_entity_decode and iconv are giving problems(as they did to me), use ut8_decode for decoding in place of html_en... and just comment out the iconv. The result may look ugly, but it works for most cases.