[英]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.