是否有部分仅在一个网站的子目录整合PHP框架最好的做法? [英] Is there a best practice for only partially integrating a PHP framework in a sub-directory of a website?

查看:121
本文介绍了是否有部分仅在一个网站的子目录整合PHP框架最好的做法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望这个问题不宽或主观的,但我所寻找的是是否存在(或正在)行之有效的方式实现一个现有的网站内Laravel框架。

I hope this question isn't to broad or subjective, but what I am looking for is whether there is (or are) well-established ways in to implement a Laravel framework within an existing website.

目前,我们正在使用自定义的CMS为我们的网站,其中包括95%的我们的需求。不过,我想提出一个子目录,其中所有的的子目录执行Laravel。我担心的是我不完全知道如何在内部工作Laravel的路由的工作(我不知道我们的CMS是否不执行其自己的路由在幕后为好),所以我不希望有矛盾的我们的CMS踩着Laravel的脚趾,反之亦然URI的问题。

We are currently using a custom CMS for our site, which covers 95% of our needs. However, I'd like to make a sub-directory of which all of it's sub-directories implement Laravel. My concern is that I'm not entirely sure how the inner-workings of Laravel's Routing works (and I'm not sure whether or not our CMS does its own routing behind the scenes as well), so I wouldn't want to have conflicting URI issues of our CMS stepping on Laravel's toes and vice versa.

我只是稍微熟悉的.htaccess规则,但将是(在Laravel子目录中的单独的.htaccess)是关键实施Laravel的路由开始在该文件夹下,并没有任何其他的网站页面上?如果我们的CMS确实做了自己的路由,将较低级别的.htaccess覆盖更高级别的?

I'm only slightly familiar with the .htaccess rules, but would that (a separate .htaccess in the Laravel sub-directory) be the key to implementing Laravel's Routing beginning at that folder down, and not for any of the other pages on the site? And if our CMS does do its own routing, would the lower-level .htaccess override the higher-level one?

,研究结果提出任何红旗上,可以在以后的发展出现的问题?

Does any of this raise any red flags on problems that could arise later in development?

推荐答案

我不认为路由将是一个问题(Laravel通常从路由的角度来看作品pretty的很好的一个子目录)。如果您使用Laravel的网址助手你都好。

I don't think routing will be a problem (Laravel normally works pretty well in a subdirectory from routing perspective). If you use the URL helpers of Laravel you're all good.

与Laravel在子目录中的更严重的问题是安全性。为避免你的整个框架code是可访问的每一个人,你会需要打破公开目录,并分开框架的其余部分。

The more serious problem with Laravel in a subdirectory is security. To avoid your whole framework code being accessible to the everyone you will need to break the public directory and the rest of the framework apart.

我建议这样的结构:

- laravel_app
--- app
--- bootstrap
--- vendor
--- ...
- document_root
--- your cms stuff
--- laravel     (laravel "public" directory renamed to whatever url you want it under)
------ index.php
------ .htaccess
------ assets

为了使这项工作,你必须编辑两个文件:

To make this work you have to edit two files:

require __DIR__.'/../../laravel_app/bootstrap/autoload.php';

$app = require_once __DIR__.'/../../laravel_app/bootstrap/start.php';

$app->run();



// ...
'public' => __DIR__.'/../../document_root/laravel',
// ...

这篇关于是否有部分仅在一个网站的子目录整合PHP框架最好的做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆