laravel - 如何在 Laravel 中的文件夹外使用 Worpress 会话
问题描述
我在从 WordPress 获取 Laravel 中的当前用户登录详细信息时遇到了麻烦
我的目录结构
/public_html/
/public_html/ here is all Laravel files like app, route, resources etc.
/public_html/shop/ here is the all WordPress Files
我正在使用服务提供程序来加载 wp-load.php 文件但是当我通过我调用它时出现错误,即
Cannot redeclare __() (previously declared in /public_html/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:851)
WordPress服务提供者
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use URL;
class WordPressServiceProvider extends ServiceProvider
{
/**
* Path to our WP installation
*
* @var string
*/
protected $bootstrapFilePath = '..\shop\wp-load.php';
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
//echo 'SESSION => '.is_user_logged_in();
/**
* Here we can enqueue any extra scripts or styles we may need.
* I loaded my frontend specific styles and scripts that were of no use to the WP site
*/
//wp_enqueue_style('frontend-styles', URL::asset('css/frontend.css'), ['dependencies'], false);
//wp_enqueue_script('frontend-scripts', URL::asset('js/frontend.js'), ['dependencies'], false, true);
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
if(\File::exists($this->bootstrapFilePath)) {
//echo 'INSIDE REGISTER';
require_once($this->bootstrapFilePath);
}else{
//echo 'OUTSIDE REGISTER'.$this->bootstrapFilePath;
}
}
}
解决方案
推荐阅读
- twig - 如何在表达式中引用 Twig 表达式
- javascript - 具有不同内容的弹出窗口?
- node.js - “PDF 文件验证失败。” 尝试通过电子邮件发送生成的 PDF 时 - DocuSign
- html - 单击图标时可扩展的导航栏
- continuous-integration - 在竹代理上运行 GUI 测试作为服务
- reactjs - React.js 动态更改元标记图像
- php - POST 表单数据和 JScript 变量到 PHP
- matlab - Matlab IMAQ 为我的 GigE 相机生成黑色图像(无图像)
- internationalization - TYPO3 创建链接并尊重目标页面的语言(Fluid,typolink)
- python - 运行 script.exe 给出 PermissionError: [Errno 13] ,但在 script.py 中运行相同的代码不会