laravel 通过laravel框架集成现有项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23293699/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Integrating existing project by laravel framework?
提问by Prasanna
I have cloned a project from github and now i need to integrate that project, so how to do with laravel framework,Should i need to create a new project then need to replace folders?or any other alternatives? becuase i am new to this framework..help me out.
我已经从 github 克隆了一个项目,现在我需要集成该项目,那么如何使用 Laravel 框架,我是否需要创建一个新项目然后需要替换文件夹?或任何其他替代方案?因为我是这个框架的新手..帮帮我。
采纳答案by Antonio Carlos Ribeiro
This is a broad question, because it depends on your project, which we don't know here.
这是一个广泛的问题,因为这取决于您的项目,我们在这里不知道。
Laravel doesn't care about where your project files are, it allows you freely to do whatever you need with all of them; most problems people have with non-Laravel projects sharing a folder with a Laravel application are related to virtual host, .htaccess configuration and/or the application they are trying to integrate. You have to understand very well how those web server things work to make your project play nicely with a Laravel application.
Laravel 不关心你的项目文件在哪里,它允许你自由地对它们做任何你需要的事情;人们在与 Laravel 应用程序共享文件夹的非 Laravel 项目中遇到的大多数问题与虚拟主机、.htaccess 配置和/或他们试图集成的应用程序有关。您必须非常了解这些 Web 服务器的工作原理,才能使您的项目与 Laravel 应用程序完美配合。
My advice is: create a subfolder inside your project and build your Laravel application on it. Configure a Virtual Host alias pointing the base URL of your Laravel application to that folder and you should be good. For example:
我的建议是:在您的项目中创建一个子文件夹并在其上构建您的 Laravel 应用程序。配置一个虚拟主机别名,将您的 Laravel 应用程序的基本 URL 指向该文件夹,您应该很好。例如:
This would be an alias for a subapp (Laravel) of myapp:
这将是 myapp 的子应用程序 (Laravel) 的别名:
Alias /subapp "/var/www/myapp/subapp/public"
<Directory /var/www/myapp/subapp>
Options Indexes Includes FollowSymLinks MultiViews
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>
And the .htaccess:
和.htaccess:
<IfModule mod_rewrite.c>
#Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)/$ / [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subapp/index.php?/ [L]
</IfModule>
Then you can have your URLs:
然后你可以有你的网址:
http://myapp
and
和
http://myapp/subapp
You can even make Laravel import some of your classes by requiring them directly in your Laravel code:
你甚至可以通过在 Laravel 代码中直接要求它们来让 Laravel 导入你的一些类:
require "../../../classes/Class.php";
If your application is based on Composer like Laravel, you can autoload your classes, by doing:
如果您的应用程序基于像 Laravel 这样的 Composer,您可以通过执行以下操作来自动加载您的类:
require "../../../vendor/autoload.php";
But if you need real integration between Laravel and your application, you have two (or more) options:
但是如果你需要在 Laravel 和你的应用程序之间真正集成,你有两个(或更多)选择:
1) Transform one of them in an API (or create an API inside it) and the other one in a client to this API.
1) 将其中一个在 API 中(或在其中创建一个 API)和客户端中的另一个转换为该 API。
2) Create a whole new Laravel project and bring your legacy code into your Laravel application, which is, blasically, create an application from scratch.
2) 创建一个全新的 Laravel 项目并将您的遗留代码带入您的 Laravel 应用程序中,也就是说,从头开始创建一个应用程序。
回答by Jonathan Cervantes
Go to your www folder
转到您的 www 文件夹
cd /var/www
Git clone your application (note that here the directory mustn't exist):
Git 克隆你的应用程序(注意这里的目录不能存在):
git clone https://github.com/antonioribeiro/application
Change directory to folder
将目录更改为文件夹
cd application
Execute composer update (if you are in a development environment)
执行 composer update (如果你在开发环境中)
composer update
Or execute composer install (if you are in a production environment)
或者执行 composer install (如果你在生产环境中)
composer install
Note that for composer install
or composer update
, the folder may actually have files and even a vendor folder created, there is not such obstacle.
请注意,对于composer install
or composer update
,文件夹实际上可能有文件甚至创建了供应商文件夹,没有这样的障碍。