Class 'FacebookSession' not found - Facebook PHP SDK v4 - php

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.

Related

How laravel classes are included?

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);

Using angelleye paypal with simplemvc framework

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.

Error when Querying Parse with PHP

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.

Php says it can't find a class which is already included

I am getting a Fatal error: Class 'Hybrid_Auth' not found When I am sure I included it like this:
require_once( $base_url."/includes/hybridauth/Hybrid/Auth.php" );//$base_url is the domain where I am running this, currently, localhost
And just to be sure, I modified the class file like:
echo "HAUTH Loaded";
class Hybrid_Auth
{
public static $version = "2.1.2";
And that echo did show up on the output page, right above that error. Any idea what to do?
Edit: I also tried:
require_once( $base_url."/includes/hybridauth/Hybrid/Auth.php" );
var_dump( file_exists($base_url."/includes/hybridauth/Hybrid/Auth.php") );die;
Which outputs:
HAUTH Loaded
boolean false
How come the require doesn't throw any error plus the echo in the file is executed, yet the next line suggests the file doesn't even exist?
EDIT 2: My urls are being rewritten via htaccess like RewriteRule ^(.*) ./route.php?path=$1 [L], so that the URLS are clean and SEO friendly, can this be responsible for this issue?
When include()ing PHP code, you must always use a filesystem path.
When using a http:// address, as a separate PHP process will start for the resource, parse the PHP, and return an empty result instead of the PHP code that you want to include.
I'm not sure about the var_dump(file_exists(...)) anomaly, but it may be similar to this. That's not what you're trying to solve, though.
Keep namespaces in mine when you are trying to use the Hybrid_Auth class within your code. If your code has a namespace, and if Hybrid_Auth doesn't declare its own, you need to reference it with a backslash, e.g. $auth = new \Hybrid_Auth();.
If namespacing is not the issue, please provide further details of the code surrounding where you're trying to use Hybrid_Auth.

Joomla: Call helper function from within a model?

I'm starting off with both php and Joomla development, and finding it difficult working within Joomla to do some fairly simple stuff. Went through the Joomla MVC example and Lynda (and have built a few simple views so far).
I have a helper file/class/function that outputs all the userids that exist in the "completed" table so I can display a link for either a new record based on that user or edit an existing user's record.
I've already used a different function in this helper file successfully in a different part of the component ( Joomla: Write and call a helper function in a component ).
When I do the same thing in the model, I'm getting this: "Fatal error: Call to protected method JModel::_createFileName() from context 'JView' in C:\wamp\www\ilplocal\libraries\joomla\application\component\view.php on line 773". When I try it in the view, works fine - but I need the output in the model.
Code:
lookups.php
abstract class LookupHelper {
public function other_functions($vars){
...
}
public function completions_exist() {
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query->SELECT(' #__completed.completed_userid as UserID');
$query->FROM (' #__completed');
$query->GROUPBY (' #__completed.completed_userid ');
$db->setQuery($query);
$result = $db->loadResultArray(0);
return $result;
}
}
In the model:
$completions_exist = Jview::loadHelper('lookups');
$completions_exist = LookupHelper::completions_exist();
This line is throwing the error: $completions_exist = Jview::loadHelper('lookups');
I've found some really vague references to something called JLoader::register to pull in helper functions but can't find any good documentation on that in Joomla except for everyone saying to just use that. SO I tried using it like so:
JLoader::register('LookupHelper', dirname( JPATH_COMPONENT_ADMINISTRATOR).DS.'helpers'.DS.'lookups.php');
$completions_exist = LookupHelper::completions_exist();
which throws this error: "Fatal error: Class 'LookupHelper' not found in C:\wamp\path\to\model\not\to\lookups.php. Tried manipulating the JLoader::register(everything here) and it doesn't effect the path of the error message.
Thoughts? Why does it work in a view and not in the model? How do I use the helper functions within a model?
Thanks!
#####EDIT
Thanks to #cppl looks like it's a path issue with the second bit of code. Also I read that the .DS. notation will be phased out in future versions - so the code that's working is:
JLoader::register('LookupHelper', JPATH_COMPONENT_ADMINISTRATOR.'/helpers/lookups.php');
$completions_exist = LookupHelper::completions_exist();
Lets break this down:
In Joomla! your components helper file should be in `/mycomponent/helpers/lookup.php'
JLoader:: is the Joomla! way to do it, but you could just as easily use PHP's require_once eg. require_once JPATH_COMPONENT_ADMINISTRATOR.'/helpers/myfunctions.php';
Is your path right? - you're providing dirname(JPATH_COMPONENT_ADMINISTRATOR).DS.'helpers'.DS.'lookups.php' but you've wrapped the path to your component in dirname which will the parent element of the path only. So JLoader is looking in /administrator/helpers/lookups.php.
JPATH_COMPONENT_ADMINISTRATOR is initialised as part of Joomla!'s renderComponent() call in it's JComponentHelper class if you apply dirname to it when it's not setup you will get back a dot (ie. current directory) so in the model you could would be passing ./helpers/lookups.php to the JLoader call.
You can call helper within model by following method:
JLoader::import('helpers.events', JPATH_COMPONENT);
this will include the file helpers/events.php from the component directory.
$_helper = new EventsHelper();
echo $_helper->getAnyInsideMethod();exit;

Categories