I am new in codeigniter . i can easily work with parse.com library on core php like this
<?php
// define location of Parse PHP SDK, e.g. location in "Parse" folder
// Defaults to ./Parse/ folder. Add trailing slash
define( 'PARSE_SDK_DIR', '../src/Parse/' );
// include Parse SDK autoloader
require_once( 'autoload.php' );
// Add the "use" declarations where you'll be using the classes
use Parse\ParseClient;
use Parse\ParseObject;
use Parse\ParseQuery;
use Parse\ParseACL;
use Parse\ParsePush;
use Parse\ParseUser;
use Parse\ParseInstallation;
use Parse\ParseException;
use Parse\ParseAnalytics;
use Parse\ParseFile;
use Parse\ParseCloud;
// Init parse: app_id, rest_key, master_key
ParseClient::initialize('id', 'id2', 'id3');
// save something to class TestObject
$testObject = ParseObject::create("TestObject");
$testObject->set("foo", "bar");
$testObject->save();
// get the object ID
echo $testObject->getObjectId();
echo '<h1>Users</h1>';
// get the first 10 users from built-in User class
$query = new ParseQuery("_User");
$query->limit(10);
$results = $query->find();
foreach ( $results as $result ) {
// echo user Usernames
echo $result->get('username') . '<br/>';
}
but i am unable to use this in codeigniter . please help me how i can add parse.com in codeigniter and use this.
please provide me some direction and example
download CI library from here
parse.com paste all code inside your application/libraries folder. make sure you have created custom config parse.php file sample
<?php
/**
* Parse keys
*/
$config['parse_appid'] = '';
$config['parse_masterkey'] = '';
$config['parse_restkey'] = '';
$config['parse_parseurl'] = 'https://api.parse.com/1/';
?>
and in your sample controller ParseSample.php try this.
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class ParseSample extends CI_Controller {
public function index()
{
$temp = $this->load->library('parse');
$testObj = $this->parse->ParseObject('testObj');
$testObj->data = array("testcol" => "it works");
$return = $testObj->save($testObj->data);
echo "<pre>";
print_r($return);
echo "<pre>";
var_dump($return);
exit;
}
}
Hope someone might feel helpful.
Related
I'm stuck on an error that I can't solve, I need help please.
Attempted to load class "MockStorageStrategy" from namespace "MangoPay\Tests\Mocks".
Did you forget a "use" statement for another namespace?
my code:
<?php
namespace App\Service;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use App\Entity\User;
use MangoPay;
use MangoPay\Tests\Mocks\MockStorageStrategy;
class CallApiService
{
private $mangoPayApi;
private $client;
public function __construct(HttpClientInterface $httpClient)
{
$this->client = $httpClient;
$this->mangoPayApi = new MangoPay\MangoPayApi();
$this->mangoPayApi->Config->ClientId = $_ENV['CLIENT_ID'];
$this->mangoPayApi->Config->ClientPassword = $_ENV['API_KEY'];
// $this->mangoPayApi->Config->TemporaryFolder = '/some/path/';
$this->mangoPayApi->OAuthTokenManager->RegisterCustomStorageStrategy(new MockStorageStrategy());
//$this->mangoPayApi->Config->BaseUrl = 'https://api.sandbox.mangopay.com';
}
public function createProfilMango($form)
{
$userMango = $this->client->request(
'POST',
'https://api.sandbox.mangopay.com/v2.01/' . '%env(CLIENT_ID)%' . '/users/natural',
[
$UserNatural = new MangoPay\UserNatural(),
$UserNatural->FirstName = $form['firstname']->getData(),
$UserNatural->LastName = $form['lastname']->getData(),
$UserNatural->Email = $form['email']->getData(),
$UserNatural->Address = new \MangoPay\Address(),
$UserNatural->Address->AddressLine1 = $form['streetNumber']->getData() . $form['address']->getData(),
$UserNatural->Address->AddressLine2 = "",
$UserNatural->Address->City = $form['city']->getData(),
$UserNatural->Address->Region = "",
$UserNatural->Address->PostalCode = $form['zipCode']->getData(),
$UserNatural->Address->Country = "FR",
$UserNatural->Birthday = $form['birthday']->getData(),
$UserNatural->Nationality = $form['nationality']->getData(),
$UserNatural->CountryOfResidence = "FR",
$Result = $this->mangoPayApi->Users->Create($UserNatural),
]
);
return $userMango;
}
}
The namespace has been checked and it is correct, concerning the dependencies the http-client and mangopay/php-sdk-v2 have been installed.
Using classes from a Test namespace are sometimes not added to the autoloader - as you should not use them in your application. A look at that package's composer.json shows this: the namespace MangoPay is routed to the folder MangoPay (see autoload for this), while the class you want to use is stored in another folder and loaded only through autoload-dev. This section is not evaluated in case you are solely using this package in your own application.
If you really want to use that class MockStorageStrategy (which is only provided for the package's internal test suite, not for being used by the application!), you should copy it to your own application namespace.
For Google adwords API I've used this library and It's working fine alone. But I am unable to integrate this library with CI 2.x.
Some code snippet is :
if (!defined('BASEPATH')) exit('No direct script access allowed');
define('SRC_PATH', APPPATH.'/third_party/Adwords/src/');
define('COMMON_PATH', 'Google/AdsApi/Common/');
define('ADWORDS_PATH', 'Google/AdsApi/AdWords/');
define('ADWORDS_VERSION', 'v201710');
// Configure include path
ini_set('include_path', implode(array(
ini_get('include_path'), PATH_SEPARATOR, SRC_PATH))
);
// Include the AdWordsUser file
require_once SRC_PATH.ADWORDS_PATH. '/AdWordsSessionBuilder.php';
require_once SRC_PATH.ADWORDS_PATH. '/Reporting/v201710/DownloadFormat.php';
require_once SRC_PATH.ADWORDS_PATH. '/Reporting/v201710/ReportDefinition.php';
require_once SRC_PATH.ADWORDS_PATH. '/Reporting/v201710/ReportDefinitionDateRangeType.php';
require_once SRC_PATH.ADWORDS_PATH. '/Reporting/v201710/ReportDownloader.php';
require_once SRC_PATH.ADWORDS_PATH. '/ReportSettingsBuilder.php';
require_once SRC_PATH.ADWORDS_PATH. '/v201710/cm/Predicate.php';
require_once SRC_PATH.ADWORDS_PATH. '/v201710/cm/PredicateOperator.php';
require_once SRC_PATH.ADWORDS_PATH. '/v201710/cm/ReportDefinitionReportType.php';
require_once SRC_PATH.ADWORDS_PATH. '/v201710/cm/Selector.php';
require_once SRC_PATH.COMMON_PATH. '/OAuth2TokenBuilder.php';
class My_adwords {
}
Getting following fatal error:
Fatal error: Interface 'Google\AdsApi\Common\AdsBuilder' not found in /var/www/html/crm2017/application/third_party/Adwords/src/Google/AdsApi/AdWords/AdWordsSessionBuilder.php on line 38
Please suggest some optimum solution.
<?php
//namespace Google\AdsApi\Examples\AdWords\v201710\Reporting;
if (!defined('BASEPATH')) exit('No direct script access allowed');
require __DIR__ . '/../third_party/Googleadwords/googleads-php-lib/vendor/autoload.php';
use Google\AdsApi\AdWords\AdWordsSession;
use Google\AdsApi\AdWords\AdWordsSessionBuilder;
use Google\AdsApi\AdWords\Reporting\v201710\ReportDownloader;
use Google\AdsApi\AdWords\Reporting\v201710\DownloadFormat;
use Google\AdsApi\AdWords\ReportSettingsBuilder;
use Google\AdsApi\Common\OAuth2TokenBuilder;
use Google\AdsApi\AdWords\v201710\cm\ReportDefinitionReportType;
use Google\AdsApi\AdWords\v201710\cm\ReportDefinitionService;
use Google\AdsApi\AdWords\v201710\cm\CampaignCriterionService;
use Google\AdsApi\AdWords\v201710\cm\Predicate;
use Google\AdsApi\AdWords\v201710\cm\PredicateOperator;
use Google\AdsApi\AdWords\v201710\cm\Paging;
use Google\AdsApi\AdWords\v201710\cm\Selector;
use Google\AdsApi\AdWords\v201710\cm\BiddingStrategyConfiguration;
use Google\AdsApi\AdWords\v201710\cm\BiddingStrategyType;
class My_adwords {
public function __construct() {
//$oAuth2Credential = new OAuth2TokenBuilder();
}
function GetCampaignsCost() {
// Get the service, which loads the required classes.
$oAuth2Credential = (new OAuth2TokenBuilder())
->fromFile()
->build();
// See: AdWordsSessionBuilder for setting a client customer ID that is
// different from that specified in your adsapi_php.ini file.
// Construct an API session configured from a properties file and the OAuth2
// credentials above.
$session = (new AdWordsSessionBuilder())
->fromFile()
->withOAuth2Credential($oAuth2Credential)
->build();
$reportFormat = DownloadFormat::CSV;
$reportQuery = 'SELECT Cost,CampaignId,BiddingStrategyType,CampaignName FROM CAMPAIGN_PERFORMANCE_REPORT DURING YESTERDAY';
// Download report as a string.
$reportDownloader = new ReportDownloader($session);
$reportSettingsOverride = (new ReportSettingsBuilder())
->includeZeroImpressions(false)
->build();
$reportDownloadResult = $reportDownloader->downloadReportWithAwql(
$reportQuery, $reportFormat, $reportSettingsOverride);
$data = $reportDownloadResult->getAsString();
}
}
I've used use instead of require_once. Just include library once and use class which needs. I've done following steps:
Composer runs outside of CodeIgnitor and all dependencies adjusted
via composer and put same folder inside application/third_party.
Make a class inside application/library which interact with
third_party. Above snippet belongs to library class.
Load library in controller and call function of library.
Hence Solved.
I am trying to use Parse in a php script.
I have done to following:
Uploaded the files 'autoload.php' and the folder 'Parse' from here to the root directory of the server
https://github.com/parseplatform/parse-php-sdk
Then I created an index.php with the following test code from here: https://www.webniraj.com/2014/08/05/parse-com-using-the-official-parse-php-sdk-v1-0-x/
// define location of Parse PHP SDK, e.g. location in "Parse" folder
// Defaults to ./Parse/ folder. Add trailing slash
define( 'PARSE_SDK_DIR', './Parse/' );
// include Parse SDK autoloader
require_once( 'autoload.php' );
// Add the "use" declarations where you'll be using the classes
use Parse\ParseClient;
use Parse\ParseObject;
use Parse\ParseQuery;
use Parse\ParseACL;
use Parse\ParsePush;
use Parse\ParseUser;
use Parse\ParseInstallation;
use Parse\ParseException;
use Parse\ParseAnalytics;
use Parse\ParseFile;
use Parse\ParseCloud;
// Init parse: app_id, rest_key, master_key
ParseClient::initialize('xxx', 'xxx', 'xxx');
// save something to class TestObject
$testObject = ParseObject::create("TestObject");
$testObject->set("foo", "bar");
$testObject->save();
// get the object ID
echo $testObject->getObjectId();
echo '<h1>Users</h1>';
// get the first 10 users from built-in User class
$query = new ParseQuery("_User");
$query->limit(10);
$results = $query->find();
foreach ( $results as $result ) {
// echo user Usernames
echo $result->get('username') . '<br/>';
}
Of course I replaced the xxx with my app_id, rest_key and master_key
When I now open index.php I am getting
Fatal error: Call to undefined function Parse\curl_init() in /Parse/ParseClient.php on line 304
Did I miss to do something?
I don't have enough reputation points to simply comment, but wanted to suggest you confirm that you have the curl PHP extension installed on your server.
phpinfo();
or
if (extension_loaded("curl"))
{
echo "cURL extension is loaded<br>";
}
else
{
echo "cURL extension is not available<br>";
}
I want to create a class of which I don't know the name. What is the best way to accomplish the following scenario in PHP?
$class_name = 'SomeClassName';
$code = "class {$class_name}_Control extends WP_Customize_Control {}";
eval( $code );
Thanks.
I just tested this and it works fine. And if you only need the class temporarily you can always throw an unlink() at the bottom. No exec() required.
<?php
// your dynamic classname
$fart = "poot";
// define your class, don't forget the "<?php"
$class = <<<YOYOYOHOMIE
<?php
class $fart{
public \$poop = "poop";
}
YOYOYOHOMIE;
// write the class to a file.
$filename = "dynamicClass".time().".php";
$fh = fopen($filename,"w+");
fwrite($fh, $class);
fclose($fh);
// require the file
require $filename;
// now your dynamically generated class is available
$tird = new $fart;
echo "<pre>";
var_dump($tird);
I want to create a backend in Wordpress for my Parse app which displays information from the app using the Parse PHP SDK.
The SDK is included and I am using the autoloader.php to load it but I keep getting the following error:
Fatal error: Class 'Parse\ParseClient' not found in http://site
I have ensured that my file path is correct.
Any suggestions.
Thanks!
define( 'PARSE_SDK_DIR', bloginfo( 'template_url' ) . '/parse/' );
// include Parse SDK autoloader
require_once('autoload.php' );
// Add the "use" declarations where you'll be using the classes
use Parse\ParseClient;
use Parse\ParseObject;
use Parse\ParseQuery;
use Parse\ParseACL;
use Parse\ParsePush;
use Parse\ParseUser;
use Parse\ParseInstallation;
use Parse\ParseException;
use Parse\ParseAnalytics;
use Parse\ParseFile;
use Parse\ParseCloud;
ParseClient::initialize('wOI4ED7sqFMI9TN9bBbwVc9WGEePcUuq15V04liY', 'lfcUvPmvT6ayZFZflLWf7rZBgbZKICuS3ppwYIxo', 'NBHXiPtiz6ECMPjnKH33P2WZwxNAMdLJEpooPCe4');
And then for the autoload.php:
<?php
/**
* You only need this file if you are not using composer.
* Adapted from the Facebook PHP SDK 4.0.x autoloader
*/
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
throw new Exception('The Parse SDK requires PHP version 5.4 or higher.');
}
/**
* Register the autoloader for the Parse SDK
* Based off the official PSR-4 autoloader example found here:
* https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md
*
* #param string $class The fully-qualified class name.
* #return void
*/
spl_autoload_register(function ($class)
{
// Parse class prefix
$prefix = 'Parse\\';
// base directory for the namespace prefix
$base_dir = defined('PARSE_SDK_DIR') ? PARSE_SDK_DIR : bloginfo( 'template_url' ) . '/parse/';
// does the class use the namespace prefix?
$len = strlen( $prefix );
if ( strncmp($prefix, $class, $len) !== 0 ) {
// no, move to the next registered autoloader
return;
}
// get the relative class name
$relative_class = substr( $class, $len );
// replace the namespace prefix with the base directory, replace namespace
// separators with directory separators in the relative class name, append
// with .php
$file = $base_dir . str_replace( '\\', '/', $relative_class ) . '.php';
echo $file;
// echo $relative_class . '<br/>';
// if the file exists, require it
if ( file_exists( $file ) ) {
require $file;
}
});
Notice that I am echoeing the $file and this points to the correct directory :/
Add the "use" declarations where you'll be using the classes. For all
of the sample code in this file:
https://github.com/ParsePlatform/parse-php-sdk
So adding use Parse\ParseClient; to your PHP file should fix the issue, add the declaration for whatever class form the Parse PHP SDK you intend to use.
if the folder structure is:
autoload.php
yourcurrentfile.php
/src
/src/Parse
you can skip / remove:
define( 'PARSE_SDK_DIR', bloginfo( 'template_url' ) . '/parse/' );
if you want to set another url just use:
define( 'PARSE_SDK_DIR', __DIR__.'/src/Parse/' );
and change to the correct URL.