最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Include LumenLaravel app in custom Wordpress template

programmeradmin0浏览0评论

I've built a small app with Lumen and now I want to include it on my wordpress site. However I have difficulty getting it to work. My approach was making a custom template and using it on a post with the URL I want. This is how it looks:

<?php /* Template Name: TestApp */ ?>

<?php
    /*
    |--------------------------------------------------------------------------
    | Create The Application
    |--------------------------------------------------------------------------
    |
    | First we need to get an application instance. This creates an instance
    | of the application / container and bootstraps the application so it
    | is ready to receive HTTP / Console requests from the environment.
    |
    */

    $app = require __DIR__.'/../../../../../my-app/bootstrap/app.php';

    /*
    |--------------------------------------------------------------------------
    | Run The Application
    |--------------------------------------------------------------------------
    |
    | Once we have the application, we can handle the incoming request
    | through the kernel, and send the associated response back to
    | the client's browser allowing them to enjoy the creative
    | and wonderful application we have prepared for them.
    |
    */

    $app->run();
?>

The $app path corresponds to a root level directory with the Lumen content inside. The idea was to use the /public/index.php as the template. It works so far, but when I query the site I get an NotFoundHttpException Error on the $app->run(); line, by RoutesRequests.php -> dispatch (line 108). I assume this is because the .htaccess isn't there, however adding that doesn't help.

How do I include standalone apps on a wordpress page?

I've built a small app with Lumen and now I want to include it on my wordpress site. However I have difficulty getting it to work. My approach was making a custom template and using it on a post with the URL I want. This is how it looks:

<?php /* Template Name: TestApp */ ?>

<?php
    /*
    |--------------------------------------------------------------------------
    | Create The Application
    |--------------------------------------------------------------------------
    |
    | First we need to get an application instance. This creates an instance
    | of the application / container and bootstraps the application so it
    | is ready to receive HTTP / Console requests from the environment.
    |
    */

    $app = require __DIR__.'/../../../../../my-app/bootstrap/app.php';

    /*
    |--------------------------------------------------------------------------
    | Run The Application
    |--------------------------------------------------------------------------
    |
    | Once we have the application, we can handle the incoming request
    | through the kernel, and send the associated response back to
    | the client's browser allowing them to enjoy the creative
    | and wonderful application we have prepared for them.
    |
    */

    $app->run();
?>

The $app path corresponds to a root level directory with the Lumen content inside. The idea was to use the /public/index.php as the template. It works so far, but when I query the site I get an NotFoundHttpException Error on the $app->run(); line, by RoutesRequests.php -> dispatch (line 108). I assume this is because the .htaccess isn't there, however adding that doesn't help.

How do I include standalone apps on a wordpress page?

Share Improve this question asked Oct 15, 2020 at 12:23 nn3112337nn3112337 1112 bronze badges 3
  • 1 I think you took the right approach, but the problem is with the application, I assume it has routes? If so then your approach won't work as is, you would need to provide the routes to the app somehow since you can't use the HTAccess method. How you would do that is Lumen specific though – Tom J Nowell Commented Oct 15, 2020 at 12:43
  • @TomJNowell yep I'm using routes. Is there no way to transfer htaccess stuff to wordpress somehow? – nn3112337 Commented Oct 15, 2020 at 13:42
  • HTAccess ffiles determine how Apache transfers the request to WP, they're not really the integral part of WP that people think they are ( but rather to tell Apache that if you have example/stuff/here, to load index.php to generate the response and not try to find a file at stuff/here. People who use Nginx don't even have HTAccess files. In this case you need to make sure that WP knows that all those routes are for that page, and then be able to either give Laravel the URL or have Laravel be able to figure it out – Tom J Nowell Commented Oct 15, 2020 at 15:22
Add a comment  | 

1 Answer 1

Reset to default 0

Okey so what I did was not using a Wordpress theme template and instead deploying the app how I normally would without WP (e.g. create the folder /my-apps/my-app and put the index and htaccess file in there). After that I wrapped the index.php manually with require '../../wp-load.php'; in the template functions (get_header() etc.)

发布评论

评论列表(0)

  1. 暂无评论