php Symfony 和 Silex 的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11270016/
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
The difference between Symfony and Silex
提问by Alex L.
I would like to try Silex but i've some questions.
我想尝试 Silex,但我有一些问题。
I know to use Symfony2 and i would like to know if Silex is very different of Symfony or it's the same thing (same operation, same code... ) ?
我知道要使用 Symfony2,我想知道 Silex 与 Symfony 是否有很大不同,还是相同的东西(相同的操作,相同的代码...)?
Moreover, Silex is recommanded for small PHP projects and Symfony for medium or big projects , it's true ?
而且,小型PHP项目推荐Silex,中大型项目推荐Symfony,是吗?
回答by igorw
A few things worth noting:
有几点值得注意:
- Silex is based on the Symfony2 components, just like the Symfony2 framework is. As such, it can be considered an alternative user interface to the components (the user being a web developer).
- Since they use the same basis, migration between them should be relatively easy.
- Just like Symfony2, Silex is mostly a controller framework. It provides you with some structure, but the model and view parts are handled by third-party libraries (such as Twig or Doctrine).
- Since your business logic should not be in your controllers anyway, if you separate that code out and keep your controllers light, the limiting factor in terms of project size will only be the amount of routes you have.
- Silex 基于 Symfony2 组件,就像 Symfony2 框架一样。因此,它可以被视为组件的替代用户界面(用户是 Web 开发人员)。
- 由于它们使用相同的基,因此它们之间的迁移应该相对容易。
- 就像 Symfony2 一样,Silex 主要是一个控制器框架。它为您提供了一些结构,但模型和视图部分由第三方库(例如 Twig 或 Doctrine)处理。
- 由于您的业务逻辑无论如何都不应该在您的控制器中,如果您将该代码分离出来并保持您的控制器轻量级,则项目大小方面的限制因素将仅是您拥有的路由数量。
That said, Silex will not give you the bundles that Symfony2 has.
也就是说,Silex 不会给你 Symfony2 所拥有的包。
回答by ivoba
Here are some interesting thoughts on when to use Silex (especially in the comments): https://web.archive.org/web/20160131151109/http://www.testically.org/2011/10/11/is-there-a-specific-situation-when-to-use-a-php-micro-framework-like-silex/
这里有一些关于何时使用 Silex 的有趣想法(尤其是在评论中):https://web.archive.org/web/20160131151109/http: //www.testically.org/2011/10/11/is-there -a-specific-situation-when-to-use-a-php-micro-framework-like-silex/
Silex itself is pretty bare, which means that if you want more then just routing and tests you will need to add specific features (DB, Twig ...) in form of Services. I recommend to take a look at some readymade Plates that provide you with this: https://github.com/lyrixx/Silex-Kitchen-Editionor https://github.com/ivoba/superleansilexplate(thats mine :))
Silex 本身非常简单,这意味着如果您想要更多,那么只是路由和测试,您将需要以服务的形式添加特定功能(DB、Twig ...)。我建议看看一些现成的板材,为您提供这个:https: //github.com/lyrixx/Silex-Kitchen-Edition或 https://github.com/ivoba/superleansilexplate(那是我的:))
Another point is that Silex has a probably lighter footprint than Symfony2, so if you need a smaller & faster site, Silex is worth a consideration.
另一点是 Silex 的占用空间可能比 Symfony2 更轻,因此如果您需要一个更小更快的站点,Silex 值得考虑。
回答by DevWL
(UPDATE) Since Symfony 2.8You can use symfony 2 as a microframework with a micro kernel controller. See short description here: symfony.com/blog/new-in-symfony-2-8-symfony-as-a-microframework. Now Symfony gives us more control over the structure and architecture. Good alternative to Silex if You prefer the Symfony 2 style.
(更新)从 Symfony 2.8 开始,您可以将 symfony 2 用作带有微内核控制器的微框架。请参阅此处的简短说明:symfony.com/blog/new-in-symfony-2-8-symfony-as-a-microframework。现在 Symfony 使我们可以更好地控制结构和架构。如果您更喜欢 Symfony 2 风格,则是 Silex 的不错替代品。
Comparing Silex to Symfony before 2.8 release
在 2.8 版本之前比较 Silex 和 Symfony
Silex microframework is based on Symfony but it's not exactly the same thing. Using a full-stack framework such as Symfony for a small project is simply overkilling the project.
Silex 微框架基于 Symfony,但并不完全相同。将 Symfony 之类的全栈框架用于小型项目简直是对项目的过度杀伤。
In a microframework, you have more flexibility to choose the tools you want to use. You can make more decisions about application architecture and logic. In a full-stack framework with some extend you would have an architecture and a logic already predefined with restrictions and limitations to its configuration.
在微框架中,您可以更灵活地选择要使用的工具。您可以对应用程序架构和逻辑做出更多决策。在带有一些扩展的全栈框架中,您将拥有一个架构和一个已经预定义的逻辑,并且对其配置有限制和限制。
Silex was designed to build up the tool rather than get the set tools that you might not need. I would say that for small projects in Symfony you would have to remove features - were in Silex you would have to add them.
Silex 旨在构建工具,而不是获取您可能不需要的工具。我会说,对于 Symfony 中的小项目,您必须删除功能 - 在 Silex 中,您必须添加它们。
It is also not true that Silex isn't fit for larger projects. Silex can be used with success for larger projects but remember that you would have to build up your tools to fit your requirements (if you need to customize the architecture and logic - perhaps this is the right way to go). Other than that, I would consider using Symfony instead, because Symfony already has bunch of tools available out of the box.
Silex 不适合大型项目也不是真的。Silex 可以成功用于大型项目,但请记住,您必须构建工具以满足您的要求(如果您需要自定义架构和逻辑 - 也许这是正确的方法)。除此之外,我会考虑使用 Symfony,因为 Symfony 已经有很多开箱即用的工具。
To conclude, Silex is good for smaller applications and for those, it can surely replace Symfony. Silex can also be used for larger projects (but for larger applications I would recommend to use full-stack framework instead, like Symfony).
总而言之,Silex 适用于较小的应用程序,对于这些应用程序,它肯定可以取代 Symfony。Silex 也可用于较大的项目(但对于较大的应用程序,我建议改用全栈框架,例如 Symfony)。
Reference for slides at: http://www.slideshare.net/dustin.whittle/silex-from-micro-to-full-stack. If you feel like it, go ahead and read some more about the Silex framework.
幻灯片参考:http: //www.slideshare.net/dustin.whittle/silex-from-micro-to-full-stack。如果您愿意,请继续阅读有关 Silex 框架的更多信息。
I also recommend watching this intro comparing Silex to Symfony: https://www.youtube.com/watch?v=RDVtnsoOysE.
我还推荐观看这个比较 Silex 和 Symfony 的介绍:https: //www.youtube.com/watch?v=RDVtnsoOysE 。
Again, a few Pro for using Silex coming from people who actually use it: https://www.youtube.com/watch?v=OJcdHGJFfLU
同样,一些使用 Silex 的专业人士来自实际使用它的人:https: //www.youtube.com/watch?v=OJcdHGJFfLU
回答by olanod
Silex is good for small projects, but it can be used for big projects as well. What I like the most of Silex is that I have complete control over my project structure but it's my responsibility if my project is well organized or not.
Also I recommend it over symfony if like me, you moved your application logic to the client side using a JS framework. For me it feels an overkill to use symfony only to serve a few json requests.
Silex 适用于小型项目,但也可用于大型项目。我最喜欢 Silex 的是我可以完全控制我的项目结构,但我的责任是我的项目是否组织得很好。
如果像我一样,你使用 JS 框架将应用程序逻辑移动到客户端,我也推荐它而不是 symfony。对我来说,只使用 symfony 来处理一些 json 请求感觉有点过头了。
回答by Lusitanian
Silex is based on the independent Symfony2 components and isn't truly considered a full-stack web application framework like Symfony is. You should only use it for very small projects that only require a few files, or you'll outgrow it pretty quickly.
Silex 基于独立的 Symfony2 组件,并不像 Symfony 那样真正被视为全栈 Web 应用程序框架。您应该只将它用于只需要几个文件的非常小的项目,否则很快就会超出它的范围。
回答by sonam
Silex is a great framework for small as well as big applications. Giving structure to the project is your responsibility in Silex. As the project becomes larger, you can nicely integrate symfony components into it although the documentation for the symfony provider is not so good especially for symfony security component.
Silex 是适用于小型和大型应用程序的出色框架。为项目提供结构是您在 Silex 的责任。随着项目变得更大,您可以很好地将 symfony 组件集成到其中,尽管 symfony 提供程序的文档不是很好,尤其是对于 symfony 安全组件。
Silex is great for prototyping projects. If you know you will be using most of the symfony components then go for symfony because you will end up with integrating almost all symfony components into silex.
Silex 非常适合原型项目。如果您知道您将使用大部分 symfony 组件,那么请选择 symfony,因为您最终会将几乎所有 symfony 组件集成到 silex 中。
In my case I needed speed right out of the box and silex provided me with the speed and although I am using most of the symfony components, it is a lot faster than symfony out of the box.
就我而言,我需要开箱即用的速度,而 silex 为我提供了速度,尽管我使用了大部分 symfony 组件,但它比开箱即用的 symfony 快得多。
回答by Ricardo Martins
At the moment I write this, Silex is in maintenance modeand it's end of life occured in June 2018.
在我写这篇文章的时候,Silex 处于维护模式,它的生命周期发生在 2018 年 6 月。
Which means you shouldn't use it anymore for new projects.
这意味着您不应再将它用于新项目。
They recommend you to use Symfony 4instead.
他们建议您改用Symfony 4。
Silex was really good and fast (maybe faster than symfony 4 for simple requests/requirements), but SF4 may bring some new stack and benefits to our applications.
Silex 真的很好而且很快(对于简单的请求/需求可能比 symfony 4 快),但是 SF4 可能会给我们的应用程序带来一些新的堆栈和好处。
Update: However, in all of my attempts on migrating from Silex to Symfony 4, the simple services took 4x times more to respond no matter what I do. Silex seems to do a much better job for simple micro services.
更新:然而,在我从 Silex 迁移到 Symfony 4 的所有尝试中,无论我做什么,简单的服务都需要 4 倍的时间来响应。Silex 似乎在简单的微服务方面做得更好。
回答by user2779489
Silex is a PHP microframework. It is use for the small project.The coding style of the symfony and the silex is almost similar to the symfony.But the symfony is use for the large projects
Silex 是一个 PHP 微框架。用于小型项目。symfony和silex的编码风格与symfony几乎相似。但symfony用于大型项目


