简体   繁体   English

在Rails中运行PHP的最佳方法是什么?

[英]What's the best way to run PHP within Rails?

I'd like to run PHP from within Rails, so I'd like to be able to compile both PHP and Ruby code in the .erb files. 我想在Rails中运行PHP,所以我希望能够在.erb文件中编译PHP和Ruby代码。 I can't figure out the best way to do this, and I'm having a hard time finding information about it without becoming completely lost. 我无法弄清楚这样做的最好方法,而且我很难找到有关它的信息而不会完全丢失。

I'm currently a Rails noob and a PHP lover so I'm using WEBrick on my Mac but Apache on my server (Windows), and I'd like to use both Rails and PHP on my Apache server if that's possible. 我现在是一个Rails noob和一个PHP爱好者所以我在我的Mac上使用WEBrick而在我的服务器上使用Apache(Windows),如果可能的话,我想在我的Apache服务器上使用Rails和PHP。 I've heard about Passenger, but I've looked in httpd.conf on my Windows server and there's no mod_rails to be found. 我听说过Passenger,但是我在Windows服务器上看了httpd.conf ,没有找到mod_rails

I don't know if I'm ready to try installing Passenger on a Windows machine. 我不知道我是否准备尝试在Windows机器上安装Passenger。 Is that even possible? 这甚至可能吗? What even is Passenger? 乘客甚至是什么?

Thanks! 谢谢!

While it's probably possible, it's a bad idea. 虽然这可能是可能的,但这是一个坏主意。 The only time PHP should run with RoR is when it is an external source that is queried such as a PHP API that RoR consumes. PHP应该与RoR一起运行的唯一时间是它是一个被查询的外部源,例如RoR消耗的PHP API。

By combining PHP with Ruby on Rails, you are going against what Ruby on Rails is designed for and will make your code a lot less portable. 通过将PHP与Ruby on Rails相结合,您将面临Ruby on Rails的设计目标,并且会使您的代码的可移植性降低。 The purpose or RoR is to make uniform code that follows the principles set by the creator. 目的或RoR是制作遵循创建者设定的原则的统一代码。 So, as Robert Harvey said, you should really truly embrace RoR. 因此,正如Robert Harvey所说,你应该真正拥抱RoR。 This will make your code easier to read for other developers and will also make asking questions on here and other forums easy since it would be a RoR question not a combined sudo question. 这将使您的代码更容易为其他开发人员阅读,并且还可以在这里和其他论坛上轻松提问,因为这将是一个RoR问题,而不是一个组合的sudo问题。

A good sign for not using PHP is that there are no obvious solutions out there for this that are pain free. 不使用PHP的一个好兆头就是没有明显的解决方案可以解决这个问题。 From that, it's pretty apparent that there is no really need for it past making development easier for somebody switching frameworks. 从那时起,很明显没有真正需要它过去使开发框架更容易开发。

So, I would suggest learning Ruby On Rails fully vs trying to combined them. 因此,我建议完全学习Ruby On Rails,然后尝试将它们组合起来。 It's going to take a while to learn all you need, but the same could be said about any framework/language. 学习所有你需要的东西需要一段时间,但任何框架/语言都可以这么说。

NOTE: This might be a helpful resource if you need it http://www.amazon.com/Rails-PHP-Developers-Pragmatic-Programmers/dp/1934356042 注意:如果您需要,这可能是一个有用的资源http://www.amazon.com/Rails-PHP-Developers-Pragmatic-Programmers/dp/1934356042

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在与Rails应用程序相同的域上运行Wordpress的最佳方法是什么? - What's the best way to run Wordpress on the same domain as a Rails application? 使用php检测浏览器的最佳方法是什么? - What's the best way to detect a browser with php? 在PHP中获取HashTable的最佳方法是什么? - What's the best way to get a HashTable in PHP? 在 php 中运行连续循环的最佳方法是什么,只有在它尚未运行时才运行? - What is the best way to run a continuous loop in php that only runs if it's not already running? 检查在jQuery模板中的PHP中是否设置参数的最佳方法是什么? - what is the best way to check if a parameter is set in PHP within a jQuery template? 在PHP中生成随机密钥的最佳方法是什么? - What is the best way to generate a random key within PHP? 在此PHP应用程序中实现用户首选项的最佳方法是什么? - What's the best way to implement user's preferences in this PHP app? 在Windows中多次异步运行PHP脚本的最佳方法是什么? - What is the best way to run a PHP script multiple times asynchronously in windows? 在PHP中多次运行相同代码的最佳方法是什么? - What is the best way to run the same code multiple times in PHP? 在特定时间运行PHP脚本的最佳方法是什么? - What is the best way to run a PHP script at a particular time?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM