首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Wordpress模板中使用Parse?

如何在Wordpress模板中使用Parse?
EN

Stack Overflow用户
提问于 2015-02-09 04:07:45
回答 2查看 1.5K关注 0票数 2

我想在Wordpress中为我的Parse应用程序创建一个后端,它使用Parse PHP SDK显示应用程序中的信息。

其中包含SDK,我正在使用autoloader.php加载它,但我一直收到以下错误:

致命错误:在http://site中找不到类'Parse\ParseClient‘

我已经确保我的文件路径是正确的。

有什么建议吗。

谢谢!

代码语言:javascript
复制
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');

然后对于autoload.php:

代码语言:javascript
复制
<?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;
  }
});

请注意,我回显的是$file,它指向正确的目录:/

EN

回答 2

Stack Overflow用户

发布于 2015-02-09 04:57:13

在要使用类的地方添加"use“声明。对于此文件中的所有示例代码:

https://github.com/ParsePlatform/parse-php-sdk

因此,将use Parse\ParseClient;添加到您的PHP文件中应该可以解决这个问题,为您打算使用的Parse PHP SDK添加任何类的声明。

票数 0
EN

Stack Overflow用户

发布于 2021-01-06 15:26:39

如果文件夹结构为:

代码语言:javascript
复制
 autoload.php
 yourcurrentfile.php
 /src
 /src/Parse

您可以跳过/删除:

代码语言:javascript
复制
define( 'PARSE_SDK_DIR', bloginfo( 'template_url' ) . '/parse/' );

如果您想设置另一个url,只需使用:

代码语言:javascript
复制
define( 'PARSE_SDK_DIR', __DIR__.'/src/Parse/' ); 

并更改为正确的URL。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28398777

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档